PHP实现http与https转化

来源:互联网 发布:linux date 北京时间 编辑:程序博客网 时间:2024/06/05 10:26

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

1
2
3
4
5
6
7
8
<!--?php <br ?--> //http转化为https
if ($_SERVER["HTTPS"]&lt;&gt;"on")
{
$xredir="https://".$_SERVER["SERVER_NAME"].
$_SERVER["REQUEST_URI"];
header("Location: ".$xredir);
}
?&gt;

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

1
2
3
4
5
6
7
8
<!--?php <br ?--> //https转化为http
if ($_SERVER["HTTPS"]=="on")
{
$xredir="http://".$_SERVER["SERVER_NAME"].
$_SERVER["REQUEST_URI"];
header("Location: ".$xredir);
}
?&gt;
0 0
原创粉丝点击