Home  >  Article  >  Backend Development  >  Solution to sharing session across http and https cross-domain

Solution to sharing session across http and https cross-domain

WBOY
WBOYOriginal
2016-07-25 08:57:271101browse
  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.



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