失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > PHP解决http和https跨域 php中http与https跨域共享session的解决方法

PHP解决http和https跨域 php中http与https跨域共享session的解决方法

时间:2019-10-14 22:26:32

相关推荐

PHP解决http和https跨域 php中http与https跨域共享session的解决方法

这篇文章主要介绍了http与https跨域共享session的解决方法,需要的朋友可以参考下

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

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

如下:

复制代码 代码如下:

$currentSessionID = session_id();

session_id($currentSessionID );

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

1,http部分:

复制代码 代码如下:

session_start();

$currentSessionID = session_id();

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

$secureServerDomain = '';

$securePagePath = '/safePages/securePage.php'

echo '点这里跳转到HTTPS 协议';

?>

2,HTTPS部分

复制代码 代码如下:

$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解决http和https跨域 php中http与https跨域共享session的解决方法》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。