Home >Backend Development >PHP Tutorial >PHP simply implements HTTP and HTTPS cross-domain sharing session solution_PHP tutorial
This article mainly introduces PHP PHP simply implements HTTP and HTTPS cross-domain sharing session solutions, the method explained in this article It’s relatively simple, friends in need can refer to it
Methods to solve cookie invalidation by session sharing under HTTP and HTTPS protocols: (Maybe not the best, but practical)
The principle is to set the session id to the local cookie,
The code is as follows:
$currentSessionID = session_id();
session_id($currentSessionID );
Simple example code:
(HTTP)
The code is as follows:
session_start();
$currentSessionID = session_id();
$_SESSION['testvariable'] = 'Session worked';
$secureServerDomain = 'www.sjolzy.cn';
$securePagePath = '/safePages/securePage.php'
echo 'Click here to jump to HTTPS protocol';
(HTTPS)
The code is as follows:
$currentSessionID = $_GET['session'];
session_id($currentSessionID);
session_start();
if (!emptyempty($_SESSION['testvariable'])) {
echo $_SESSION['testvariable'];
} else {
echo 'Session did not work.';
}
There is a bit of a security issue, because the transmission of the session id is not encrypted in this way, and others can sniff and detect it, obtain the session id and then obtain your session data. So if necessary, you can consider encrypting this ID.
The cookie setting of a magento site has been invalid. I struggled for many days. Finally, I realized that HTTP and HTTPS cross-domain made the COOKIE invalid. .