Http and https cross-domain sharing session solution in php, httpssession_PHP tutorial

Source: Internet
Author: User
Http and https cross-origin sharing session in php: httpssession. In php, http and https cross-origin sharing sessions are solved. httpssession has encountered session sharing under the HTTP and HTTPS protocols to solve the problem of cookie failure. a temporary solution is provided here. Http and https cross-domain sharing session in php, httpssession

Session sharing in HTTP and HTTPS protocols solves the problem of cookie failure. 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 .jb51.net ';
$ 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.

Session sharing in the HTTP and HTTPS protocols solves the problem of cookie failure. a temporary solution is provided here ....

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.