php header方法跳轉(zhuǎn)頁(yè)面:1、立即跳轉(zhuǎn),代碼為【header('location:other.php')】;2、提示跳轉(zhuǎn),代碼為【header('refresh:3,url=other.php');echo '3s 后跳轉(zhuǎn)'】。
php header方法跳轉(zhuǎn)頁(yè)面:
header()為php函數(shù),向?yàn)g覽器發(fā)送指定命令
html:
<meta http-equiv="refresh" content="3;url=other.php"/>立即跳轉(zhuǎn):
header('location:other.php');//file_put_contents('bee.txt','execute');die;執(zhí)行header時(shí)候,并不是立即結(jié)束,而是會(huì)把頁(yè)面執(zhí)行完畢;在header前面不能有任何輸出,若有開啟輸出緩沖則不提示錯(cuò)誤,
php.ini->output_buffering = 4096|off提示跳轉(zhuǎn):
header('refresh:3,url=other.php');echo '3s 后跳轉(zhuǎn)';//由于只是普通頁(yè)面展示,提示的樣式容易定制die;封裝的跳轉(zhuǎn)函數(shù):
/* *跳轉(zhuǎn) *@param $url 目標(biāo)地址 *@param $info 提示信息 *@param $sec 等待時(shí)間 *return void*/function jump($url,$info=null,$sec=3){ if(is_null($info)){ header("location:$url"); }else{ // header("refersh:$sec;url=$url"); echo"<meta http-equiv=\\\\"refresh\\\\" content=".$sec.";url=".$url.">"; echo $info; } die;}相關(guān)學(xué)習(xí)推薦:php編程從入門到精通