Home  >  Article  >  Backend Development  >  PHP simply implements HTTP and HTTPS cross-domain sharing session solutions, httpssession_PHP tutorial

PHP simply implements HTTP and HTTPS cross-domain sharing session solutions, httpssession_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:52:21782browse

PHP simply implements a solution for cross-domain sharing of sessions under HTTP and HTTPS, httpssession

A solution for session sharing under HTTP and HTTPS protocols to resolve cookie failure: (Maybe not the best, but Practical)

The principle is to set the session id to the local cookie,
Copy code The code is as follows:
$currentSessionID = session_id();
session_id($currentSessionID );

Simple example code:

(HTTP)
Copy code 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 the HTTPS protocol';

(HTTPS)
Copy code 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, and I struggled for many days. Finally, I realized that the cross-domain between HTTP and HTTPS made the cookie invalid. .

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1008020.htmlTechArticlePHP simply implements HTTP and HTTPS cross-domain sharing session solutions, httpssession session sharing under HTTP and HTTPS protocols solves cookie failure Method: (maybe not the best, but practical)...
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