HTTP、HTTPS協議下跨域解決session共享的辦法,也許不是最好的,但是比較實用。如下是具體的解決方案。
$currentSessionID=session_id();session_id($currentSessionID);
簡單示例代碼:
(HTTP)
<?phpsession_start(); $currentSessionID=session_id(); $_SESSION['username']='Alixixi'; echo '<a href="https://www.Alixixi.com/jquery.php?session="'.$currentSessionID.'">點擊這里跳轉到HTTPS協議下</a>';
(HTTPS)
<?php$currentSessionID=$_GET['session'];session_id($currentSessionID);session_start();if(!empty($_SESSION['username'])){ echo $_SESSION['username'];}else{ echo 'Session did not work.';}有點安全性的問題,因為這樣子的話session id的傳輸是沒加密的,別人可以嗅探偵測到,獲取這個session id進而獲取你的session數據。所以有必要的話可以考慮加密這個id值。
關于PHP解決HTTP和HTTPS跨域共享session的方法及代碼實例的內容寫到這里就結束啦,您可以收藏本頁網址http://www.survivalescaperooms.com/biancheng/a/2018091494234.shtml方便下次再訪問哦。
新聞熱點
疑難解答