Blogger Information
Blog 263
fans 3
comment 2
visits 113258
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
HTTP与HTTPS转换,(php代码部分)
福哥的博客
Original
2213 people have browsed it

  最近在写PHP程序时,需要使浏览器在https和http之间转化,上网搜索相关信息,无奈只有最近在写PHP程序时,需要使浏览器在https和http之间转化,上网搜索相关信息,无奈只有一篇介绍用ASP实现“在http和https之间转化”的文章,于是只好行写了用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);  
}   
?>
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ||
 (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ?
  'https://' : 'http://';


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post