php中http与https跨域共享session的解决方法
2015-01-24信息快讯网
这篇文章主要介绍了http与https跨域共享session的解决方法,需要的朋友可以参考下
遇到了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 . '?session="' . $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中new static() 和 new self() 的区别介绍
php计划任务之ignore_user_abort函数实现方法
CI框架中site_url()和base_url()的区别
WampServer下安装多个版本的PHP、mysql、apache图文教程
PHP和Shell实现检查SAMBA与NFS Server是否存在
php基于表单密码验证与HTTP验证用法实例
VPS中使用LNMP安装WordPress教程
php连接与操作PostgreSQL数据库的方法
PHP_SELF,SCRIPT_NAME,REQUEST_URI区别
php将access数据库转换到mysql数据库的方法
php实现refresh刷新页面批量导入数据的方法
php获取数组元素中头一个数组元素值的实现方法
php将textarea数据提交到mysql出现很多空格的解决方法
thinkphp中session和cookie无效的解决方法
php提示Failed to write session data错误的解决方法
php中magic_quotes_gpc对unserialize的影响分析
php中get_meta_tags()、CURL与user-agent用法分析
php自定文件保存session的方法
php通过session防url攻击方法
php实现的SESSION类
PHP实现抓取HTTPS内容
使用PHP Socket 编程模拟Http post和get请求
php中HTTP_REFERER函数用法实例
PHP中Header使用的HTTP协议及常用方法小结
php之curl实现http与https请求的方法