Home >Backend Development >PHP Tutorial >Solution to cross-domain sharing session between http and https in php, httpssession_PHP tutorial

Solution to cross-domain sharing session between http and https in php, httpssession_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:11:16932browse

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

Encountered the problem of session sharing under HTTP and HTTPS protocols to solve the problem of cookie failure. Here is a temporary solution.
Implementation principle: Set the session id to the local cookie.

As follows:

Copy code The code is as follows:

$currentSessionID = session_id();
session_id($currentSessionID );

The following is the implementation code, which is divided into http and https parts.

1, http part:

Copy code The code is as follows:

session_start();
$currentSessionID = session_id();
$_SESSION['testvariable'] = 'Session worked';
$secureServerDomain = 'www.jb51.net';
$securePagePath = '/safePages/securePage.php'
echo 'Click here to jump to HTTPS protocol';
?>

2, HTTPS part

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.';
}
?>

Description:
There is a bit of a security issue. The transmission of the session id is not encrypted and can be detected by sniffing, obtaining the session id and then obtaining the session data.
It is recommended to encrypt this ID.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/930491.htmlTechArticleSolution to cross-domain sharing session between http and https in php, httpssession encounters session sharing solution under HTTP and HTTPS protocols To solve the problem of cookie invalidation, here is a temporary solution. ...
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