某些托管服务提供商(如HostGator)为帐户提供共享SSL证书。这意味着我的HTTPS链接是与HTTP不同的域。
即:网址类似于http://www.mydomain.com和https://secure123.hostgator.com/~bill/
我正在尝试将用户登录到安全域,设置会话变量,然后重定向到主页。但是,执行此操作时,会话变量将丢失。
不安全的Index.php:
<?php session_start();
echo $_SESSION['name'];
?>
<html><body>
<p><a href="https://secure123.hostgator.com/~bill/login.php">Login</a></p>
</body></html>
安全登录.php:
<?php session_start();
$_SESSION['name'] = "Bill";
header("location: http://www.mydomain.com/index.php")
?>
如何确保http和https上的所有文件都能读取会话变量?
答案 0 :(得分:2)
您可以通过GET提供会话ID。
header("location: http://www.mydomain.com/index.php?PHPSESSID=".session_id());
另一方面,你可以开始session.use_trans_sid
或者使用函数session_id()
设置会话ID