PHP简单实现HTTP和HTTPS跨域共享session解决办法,httpssession_PHP教程

WBOY
Release: 2016-07-13 09:52:21
Original
685 people have browsed it

PHP简单实现HTTP和HTTPS跨域共享session解决办法,httpssession

HTTP、HTTPS协议下session共享解决cookie失效 的办法:(也许不是最好的,但是实用)

原理就是把session id设置到本地的cookie,
复制代码 代码如下:
$currentSessionID = session_id();
session_id($currentSessionID );

简单事例代码:

(HTTP)
复制代码 代码如下:
session_start(); 
$currentSessionID = session_id(); 
$_SESSION['testvariable'] = 'Session worked'; 
$secureServerDomain = 'www.sjolzy.cn'; 
$securePagePath = '/safePages/securePage.php' 
echo '点击这里跳转到HTTPS 协议下';

(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。

一个magento站的cookie设置一直失效,纠结好多天,最后明悟是HTTP和HTTPS跨域 使COOKIE失效了。。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1008020.htmlTechArticlePHP简单实现HTTP和HTTPS跨域共享session解决办法,httpssession HTTP、HTTPS协议下session共享解决cookie失效 的办法:(也许不是最好的,但是实用)...
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!