首頁  >  文章  >  後端開發  >  php header方法跳到頁面問題

php header方法跳到頁面問題

coldplay.xixi
coldplay.xixi原創
2020-07-27 15:37:453628瀏覽

php header方法跳轉頁:1、立即跳轉,程式碼為【header('Location:other.php')】;2、提示跳轉,程式碼為【header('Refresh:3, Url=other.php');echo '3s 後跳躍'】。

php header方法跳到頁面問題

php header方法跳到頁面:

header()為php函數,向瀏覽器發送指定命令

html:

<meta http-equiv="Refresh" content="3;url=other.php"/>

立即跳轉:

header(&#39;Location:other.php&#39;);
//file_put_contents(&#39;bee.txt&#39;,&#39;execute&#39;);
die;

執行header時候,並不是立即結束,而是會把頁面執行完畢;在header前面不能有任何輸出,若有開啟輸出緩衝則不提示錯誤,

php.ini->output_buffering = 4096|OFF

提示跳轉:

header(&#39;Refresh:3,Url=other.php&#39;);
echo &#39;3s 后跳转&#39;;
//由于只是普通页面展示,提示的样式容易定制
die;

封裝的跳轉函數:

/*
 *跳转
 *@param $url 目标地址
 *@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;
}

#相關學習推薦:PHP程式設計從入門到精通

#

以上是php header方法跳到頁面問題的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn