php中http与https跨域共享session的解决方法_php教程-查字典教程网
php中http与https跨域共享session的解决方法
php中http与https跨域共享session的解决方法
发布时间:2016-12-29 来源:查字典编辑
摘要:遇到了HTTP、HTTPS协议下session共享解决cookie失效的问题,这里提供一个临时解决办法。实现原理:把sessionid设置到...

遇到了HTTP、HTTPS协议下session共享解决cookie失效的问题,这里提供一个临时解决办法。

实现原理:把session id设置到本地的cookie。

如下:

复制代码 代码如下:

$currentSessionID = session_id();

session_id($currentSessionID );

以下是实现代码,分为http与https两部分。

1,http部分:

复制代码 代码如下:

<?php

session_start();

$currentSessionID = session_id();

$_SESSION['testvariable'] = 'Session worked';

$secureServerDomain = 'www.jb51.net';

$securePagePath = '/safePages/securePage.php'

echo '<a href="https://' . $secureServerDomain . $securePagePath . '"' . $currentSessionID . '">点这里跳转到HTTPS 协议</a>';

?>

2,HTTPS部分

复制代码 代码如下:

<?php

$currentSessionID = $_GET['session'];

session_id($currentSessionID);

session_start();

if (!emptyempty($_SESSION['testvariable'])) {

echo $_SESSION['testvariable'];

} else {

echo 'Session did not work.';

}

?>

说明:

有点安全问题,session id的传输是没加密的,可以嗅探侦测到,获取这个session id进而获取session数据。

建议加密此id。

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新php教程学习
    热门php教程学习
    编程开发子分类