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

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

$currentSessionID=session_id();
session_id($currentSessionID);

简单示例代码:

(HTTP)

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

(HTTPS)

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

 

有点安全性的问题,因为这样子的话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错误



Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function