Home > php教程 > php手册 > HTTP和HTTPS跨域共享session解决办法

HTTP和HTTPS跨域共享session解决办法

WBOY
Release: 2016-06-21 08:47:19
Original
1869 people have browsed it

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

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

简单示例代码:

(HTTP)

<?php
session_start();  
$currentSessionID=session_id();  
$_SESSION['username']='Alixixi';  
echo '<a href="https://www.Alixixi.com/jquery.php?session="'.$currentSessionID.'">点击这里跳转到HTTPS协议下</a>';
Copy after login

(HTTPS)

<?php
$currentSessionID=$_GET['session'];
session_id($currentSessionID);
session_start();
if(!empty($_SESSION['username'])){
      echo $_SESSION['username'];
}else{  
      echo 'Session did not work.';
}
Copy after login

 

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

PHP加密解密的函数

您可能感兴趣的文章

  • 常见的HTTP状态码(HTTP Status Code)说明
  • php自定义session保存目录
  • XDebug的进度条停在57%,提示waiting for XDebug session错误的解决办法
  • PHP实现同服务器多个二级域名共享 SESSION 数据
  • jquery获取同辈元素集合,jquery siblings 用法总结
  • php获取某段时间内每个月的方法,返回由这些月份组成的数组
  • php利用P3P头实现跨域设置cookie
  • 该如何解决php运行出现Call to undefined function curl_init错误



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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template