《PHP應用:php中http與https跨域共享session的解決方法》要點:
本文介紹了PHP應用:php中http與https跨域共享session的解決方法,希望對您有用。如果有疑問,可以聯系我們。
遇到了HTTP、HTTPS協議下session共享解決cookie失效的問題,這里提供一個臨時解決辦法.
實現原理:把session id設置到本地的cookie.PHP教程
如下:PHP教程
代碼如下:
$currentSessionID = session_id();
session_id($currentSessionID );
以下是實現代碼,分為http與https兩部分.PHP教程
1,http部分:PHP教程
代碼如下:
<?php
session_start();?
$currentSessionID = session_id();?
$_SESSION['testvariable'] = 'Session worked';?
$secureServerDomain = 'www.jb51.net';?
$securePagePath = '/safePages/securePage.php'?
echo '<a href="https://' . $secureServerDomain . $securePagePath . '?session="' . $currentSessionID . '">點這里跳轉到HTTPS 協議</a>';
?>
2,HTTPS部分PHP教程
代碼如下:
<?php
$currentSessionID = $_GET['session'];
session_id($currentSessionID);
session_start();
if (!emptyempty($_SESSION['testvariable'])) {
????? echo $_SESSION['testvariable'];
} else {?
????? echo 'Session did not work.';
}
?>
說明:
有點平安問題,session id的傳輸是沒加密的,可以嗅探偵測到,獲取這個session id進而獲取session數據.
建議加密此id.PHP教程
《PHP應用:php中http與https跨域共享session的解決方法》是否對您有啟發,歡迎查看更多與《PHP應用:php中http與https跨域共享session的解決方法》相關教程,學精學透。維易PHP學院為您提供精彩教程。
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/13237.html