php header方法跳轉(zhuǎn)頁面:1、立即跳轉(zhuǎn),代碼為【header('Location:other.php')】;2、提示跳轉(zhuǎn),代碼為【header('Refresh:3,Url=other.php');echo '3s 后跳轉(zhuǎn)'】。
php header方法跳轉(zhuǎn)頁面:
header()
為php函數(shù),向瀏覽器發(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時候,并不是立即結(jié)束,而是會把頁面執(zhí)行完畢;在header前面不能有任何輸出,若有開啟輸出緩沖則不提示錯誤,
php.ini->output_buffering = 4096|OFF
提示跳轉(zhuǎn):
header('Refresh:3,Url=other.php'); echo '3s 后跳轉(zhuǎn)'; //由于只是普通頁面展示,提示的樣式容易定制 die;
封裝的跳轉(zhuǎn)函數(shù):
/* *跳轉(zhuǎn) *@param $url 目標(biāo)地址 *@param $info 提示信息 *@param $sec 等待時間 *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編程從入門到精通