Home > php教程 > php手册 > body text

PHP实现http与https转化

WBOY
Release: 2016-06-13 10:43:37
Original
1442 people have browsed it

 

 最近在写PHP程序时,需要使浏览器在https和http之间转化,上网搜索相关信息,无奈只有最近在写PHP程序时,需要使浏览器在https和http之间转化,上网搜索相关信息,无奈只有一篇介绍用ASP实现“在http和https之间转化”的文章,于是只好行写了用PHP实现http与https转化的代码。

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

view plainprint?

//http转化为https   

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

{  

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

$_SERVER["REQUEST_URI"];  

header("Location: ".$xredir);  

}   

?>  

 

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

view plainprint?

//https转化为http   

if ($_SERVER["HTTPS"]=="on")  

{  

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

$_SERVER["REQUEST_URI"];  

header("Location: ".$xredir);  

}   

?>  

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!