PHP简单实现HTTP和HTTPS跨域共享session解决办法
HTTP、HTTPS协议下session共享解决cookie失效的办法:(也许不是最好的,但是实用)
原理就是把sessionid设置到本地的cookie,
$currentSessionID=session_id(); session_id($currentSessionID);
简单事例代码:
(HTTP)
session_start(); $currentSessionID=session_id(); $_SESSION['testvariable']='Sessionworked'; $secureServerDomain='www.sjolzy.cn'; $securePagePath='/safePages/securePage.php' echo'<ahref="https://'.$secureServerDomain.$securePagePath.'?session="'.$currentSessionID.'">点击这里跳转到HTTPS协议下</a>';
(HTTPS)
$currentSessionID=$_GET['session']; session_id($currentSessionID); session_start(); if(!emptyempty($_SESSION['testvariable'])){ echo$_SESSION['testvariable']; }else{ echo'Sessiondidnotwork.'; }
有点安全性的问题,因为这样子的话sessionid的传输是没加密的,别人可以嗅探侦测到,获取这个sessionid进而获取你的session数据。所以有必要的话可以考虑加密这个id。
一个magento站的cookie设置一直失效,纠结好多天,最后明悟是HTTP和HTTPS跨域使COOKIE失效了。。