HTTP和HTTPS跨域共享php session方法

WBOY
Release: 2016-06-20 13:04:10
Original
910 people have browsed it

HTTP、HTTPS协议下跨域解决php session共享的办法,也许不是最好的,但是比较实用。

如下是具体的解决方案。

$currentSessionID=session_id();session_id($currentSessionID);
Copy after login

简单示例代码:

(HTTP)

<?php</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>';
Copy after login

(HTTPS)

<span style="font-size: 14px;"><?php</span></p><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;">
Copy after login

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


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!