php实现http与https转化

如果网页使用https访问,在网页开头加入以下代码:  

   <?php 

    //http转化为https  

      if ($_SERVER["HTTPS"]<>"on") 

     { 

      $xredir="https://".$_SERVER["SERVER_NAME"]. 

      $_SERVER["REQUEST_URI"]; 

      header("Location: ".$xredir); 

      }  

      ?> 

 

如果网页使用http访问,在网页开头加入以下代码:

      <?php  
      //https转化为http   
      if ($_SERVER["HTTPS"]=="on")  
     {  
      $xredir="http://".$_SERVER["SERVER_NAME"].  
      $_SERVER["REQUEST_URI"];  
      header("Location: ".$xredir);  
      }   
      ?>  

 

 

posted @ 2018-08-16 18:02  噼里啪啦哒哒哒  阅读(1712)  评论(0编辑  收藏  举报