解决HTTP和HTTPS跨域共享session的方法及代码实例

HTTP、HTTPS协议下跨域解决session共享的办法,也许不是最好的,但是比较实用。如下是具体的解决方案。
$currentSessionID=session_id();
session_id($currentSessionID);

简单示例代码:

(HTTP)

<?php
session_start();  
$currentSessionID=session_id();  
$_SESSION['username']='Alixixi'; https:www.cqxftyyj.com 
echo '<a href="https://www.Alixixi.com/jquery.php?session="'.$currentSessionID.'">点击这里跳转到HTTPS协议下</a>';

(HTTPS)

<?php
$currentSessionID=$_GET['session'];
session_id($currentSessionID);
session_start();
if(!empty($_SESSION['username'])){
      echo $_SESSION['username'];
}else{https:www.cqxftyyj.com
echo 'Session did not work.'; }

有点安全性的问题,因为这样子的话session id的传输是没加密的,别人可以嗅探侦测到,获取这个session id进而获取你的session数据。所以有必要的话可以考虑加密这个id值。

原文地址:https://www.cnblogs.com/zqw111/p/12928616.html