Solution to sharing session across http and https cross-domain

WBOY
Release: 2016-07-25 08:57:27
Original
1092 people have browsed it
  1. $currentSessionID = session_id();
  2. session_id($currentSessionID );
Copy code

The following is the implementation code, which is divided into http and https parts.

1, http part:

  1. session_start();
  2. $currentSessionID = session_id();
  3. $_SESSION['testvariable'] = 'Session worked';
  4. $secureServerDomain = 'www.sjolzy.cn';
  5. $securePagePath = '/safePages/securePage.php'
  6. echo 'Click here to jump To HTTPS protocol';
  7. ?>
Copy code

2, HTTPS part

  1. $currentSessionID = $_GET['session'];
  2. session_id($currentSessionID);
  3. session_start();
  4. if (!emptyempty($_SESSION['testvariable'])) {
  5. echo $_SESSION['testvariable'];
  6. } else {
  7. echo 'Session did not work.';
  8. }
  9. ?>
Copy code

Instructions: There is a bit of a security issue. The transmission of the session id is not encrypted and can be detected by sniffing, obtaining the session id and then obtaining the session data. It is recommended to encrypt this ID.



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