站长论坛

标题: PHP实现http与https转化 [打印本页]

作者: tznktg    时间: 2010-8-5 11:36
标题: PHP实现http与https转化
最近在写PHP程序时,需要使浏览器在https和http之间转化,上网搜索相关信息,无奈只有最近在写PHP程序时,需要使浏览器在https和http之间转化,上网搜索相关信息,无奈只有一篇介绍用ASP实现“在http和https之间转化”的文章,于是只好行写了用PHP实现http与https转化的代码。
  如果网页使用https访问,在网页开头加入以下代码:

view plaincopy to clipboardprint?
1.<?php   
2.//http转化为https   
3.if ($_SERVER["HTTPS"]<>"on")   
4.{   
5.$xredir="https://".$_SERVER["SERVER_NAME"].   
6.$_SERVER["REQUEST_URI"];   
7.header("Location: ".$xredir);   
8.}   
9.?>   
<?php
//http转化为https
if ($_SERVER["HTTPS"]<>"on")
{
$xredir="https://".$_SERVER["SERVER_NAME"].
$_SERVER["REQUEST_URI"];
header("Location: ".$xredir);
}
?>

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

view plaincopy to clipboardprint?
1.<?php   
2.//https转化为http   
3.if ($_SERVER["HTTPS"]=="on")   
4.{   
5.$xredir="http://".$_SERVER["SERVER_NAME"].   
6.$_SERVER["REQUEST_URI"];   
7.header("Location: ".$xredir);   
8.}   
9.?>




欢迎光临 站长论坛 (http://tzlink.com/bbs/) Powered by Discuz! X3.2