http、https协议下跨域解决php session共享的办法,也许不是最好的,但是比较实用。
如下是具体的解决方案。
$currentSessionID=session_id();session_id($currentSessionID);
简单示例代码:
(HTTP)
<?php</p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p><p>session_start();</p><p><span style="font-family: Arial, Helvetica, sans-serif; font-size: 14px;">$currentSessionID=session_id(); </span></p><p>$_SESSION['username']='scutephp';</p><p>echo '<a href="https://www.scutephp.com/jquery.php?session="'.$currentSessionID.'">点击这里跳转到HTTPS协议下</a>';
(HTTPS)
<span style="font-size: 14px;"><?php</span></p>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/ai/1779">
<img src="https://img.php.cn/upload/ai_manual/000/000/000/175680358236649.png" alt="奇域">
</a>
<div class="aritcle_card_info">
<a href="/ai/1779">奇域</a>
<p>奇域是一个专注于中式美学的国风AI绘画创作平台</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="奇域">
<span>30</span>
</div>
</div>
<a href="/ai/1779" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="奇域">
</a>
</div>
<p>$currentSessionID=$_GET['session'];</p><p>session_id($currentSessionID);</p><p>session_start();</p><p>if(!empty($_SESSION['username'])){ </p><p>echo $_SESSION['username'];</p><p>}else{ </p><p> echo 'Session did not work.';</p><p>}<span style="font-size: 14px; font-family: Arial, Helvetica, sans-serif;">有点安全性的问题,因为这样子的话session id的传输是没加密的,别人可以嗅探侦测到,获取这个session id进而获取你的session数据。所以有必要的话可以考虑加密这个id值。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号