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

PHP simply implements HTTP and HTTPS cross-domain sharing session solution_PHP tutorial

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

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

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. .

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1007652.htmlTechArticlePHP simply implements HTTP and HTTPS cross-domain sharing session solutions. This article mainly introduces PHP to simply implement HTTP and HTTPS. Cross-domain session sharing solution. The method explained in this article is relatively simple and requires...
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