This article mainly introduces the solution to cross-origin session sharing between http and https. For more information, see
This article mainly introduces the solution to cross-origin session sharing between http and https. For more information, see
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.