久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      php如何實現(xiàn)header跳轉(zhuǎn)

      php如何實現(xiàn)header跳轉(zhuǎn)

      php實現(xiàn)header跳轉(zhuǎn)的方法以及注意事項:

      header()函數(shù)是PHP中進行頁面跳轉(zhuǎn)的一種十分簡單的方法。header()函數(shù)的主要功能是將HTTP協(xié)議標(biāo)頭(header)輸出到瀏覽器。

      header()函數(shù)的定義如下:

      void header (string string [,bool replace [,int http_response_code]])

      可選參數(shù)replace指明是替換前一條類似標(biāo)頭還是添加一條相(www.php.cn)同類型的標(biāo)頭,默認(rèn)為替換。

      第二個可選參數(shù)http_response_code強制將HTTP相應(yīng)代碼設(shè)為指定值。 header函數(shù)中Location類型的標(biāo)頭是一種特殊的header調(diào)用,常用來實現(xiàn)頁面跳轉(zhuǎn)。注意:

      1.location和“:”號間不能有空格,否則不會跳轉(zhuǎn)。
      2.在用header前不能有任何的輸出。
      3.header后的PHP代碼還會被執(zhí)行。例如,將瀏覽器重定向到php.cn

      <?php  //重定向瀏覽器 header("Location: https://www.php.cn");  //確保重定向后,后續(xù)代碼不會被執(zhí)行 exit; ?>

      1、php跳轉(zhuǎn)代碼一句話式:

      <?php $url = $_GET['url']; Header("Location:$url"); ?>

      2、php跳轉(zhuǎn)代碼if判斷式:

      復(fù)制代碼 代碼如下:

      if($_COOKIE["u_type"]){  header('location:register.php'); } else{  setcookie('u_type','1','86400*360');//設(shè)置cookie長期有效  header('location:zc.html');

      :保存為zc.php,當(dāng)用戶訪問zc.php時,判斷一個cookie是否存在,如果存(www.php.cn)在就跳轉(zhuǎn)到register.php,如果不存在則創(chuàng)建cookie然后跳轉(zhuǎn)到zc.html.

      URL重定向函數(shù)

      function redirect($url, $time=0, $msg=”) {  //多行URL地址支持 $url = str_replace(array(“n”, “r”), ”, $url);  if ( empty($msg) )  $msg = “系統(tǒng)將在{$time}秒之后自動跳轉(zhuǎn)到{$url}!”; if (!headers_sent()) {  // redirect  if (0 === $time) {  header(‘Location: ‘ . $url);  } else {  header(“refresh:{$time};url={$url}”); echo($msg);  }  exit();  } else {  $str = “<meta http-equiv='Refresh' content='{$time};URL={$url}'>”; if ($time != 0)  $str .= $msg;  exit($str);  }  }

      上面的不能返回404狀態(tài),如果是頁面跳轉(zhuǎn)之后返回404狀態(tài)代碼我們可如下操作

      function getref()  {  $url = @$_SERVER['HTTP_REFERER'];  if( !empty( $url ) )  {  if( !strstr($url ,'jb51.net' ) && !strstr($url,'jb51.net'))  {  @header("http/1.1 404 not found");  @header("status: 404 not found");  include("404.html");//跳轉(zhuǎn)到某一個頁面,推薦使用這種方法  exit();  }  }  else  {  @header("http/1.1 404 not found");  @header("status: 404 not found");  include("404.html");//跳轉(zhuǎn)到某一個頁面,推薦使用這種方法  exit();  }  }

      如果要做301也差不多

      <?php  $the_host = $_SERVER['HTTP_HOST'];  $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';  if($the_host !== 'www.jb51.net')  {   //echo $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];   header('HTTP/1.1 301 Moved Permanently');   header('Location: https://www.jb51.net' . $_SERVER['PHP_SELF'] . $request_uri);  }  ?>

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號