Solution to http and https cross-domain sharing session in php

Source: Internet
Author: User
This article mainly introduces how to solve the problem of cross-origin session sharing between http and https. For more information, see session sharing under HTTP and HTTPS protocols, A temporary solution is provided here.
Implementation principle: Set the session id to a local cookie.

As follows:

The code is as follows:


$ CurrentSessionID = session_id ();
Session_id ($ currentSessionID );

The following is the implementation code, which consists of http and https.

1. http:

The code is as follows:


<? Php
Session_start ();
$ CurrentSessionID = session_id ();
$ _ SESSION ['testvariable'] = 'session worked ';
$ SecureServerDomain = 'www .bitsCN.com ';
$ SecurePagePath = '/safePages/securePage. php'
Echo 'click here to jump to the HTTPS protocol ';
?>

2. HTTPS section

The code is as follows:


<? Php
$ CurrentSessionID = $ _ GET ['session'];
Session_id ($ currentSessionID );
Session_start ();
If (! Emptyempty ($ _ SESSION ['testvariable']) {
Echo $ _ SESSION ['testvariable'];
} Else {
Echo 'session did not work .';
}
?>

Note:
A bit of security problems, the transfer of session id is not encrypted, can be detected by sniffing, get this session id and then get session data.
We recommend that you encrypt this id.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.