在项目中,往往为了安全, 登录,注册等等一些敏感资料的时候都会需要进行https进行加密传送数据,防止数据被拦截篡改等等:
http转换为https:
if($_SERVER['HTTPS'] <> 'on'){
$url = "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
header("Location: ".$url);
}
https转换为http
if($_SERVER['HTTPS']=='on'){
$url = "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
header("Location: ".$url);
}