php - 在 HTTP 和 HTTPS 之间传递 session 变量

标签 php session ssl authentication https

某些托管提供商(例如 HostGator)为帐户提供共享 SSL 证书。这意味着我的 HTTPS 链接与我的 HTTP 链接是不同的域。

即:网址类似于 http://www.mydomain.comhttps://secure123.hostgator.com/~bill/

我正在尝试让用户登录安全域,设置 session 变量,然后重定向到主页。但是,执行此操作时, session 变量会丢失。

不安全的 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")
?>

如何确保 session 变量能够被 http 和 https 上的所有文件读取?

最佳答案

您可以通过 GET 提供您的 session ID。

header("location: http://www.mydomain.com/index.php?PHPSESSID=".session_id());

在另一侧您可以打开session.use_trans_sid

或者使用函数 session_id() 设置 session ID

Manual: Passing the Session ID

关于php - 在 HTTP 和 HTTPS 之间传递 session 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17437705/

相关文章:

oracle - 为 Oracle 12 配置 SSL 连接

PHP 在第 31 个月的日期添加月份至今

php - 如果在 mysql 表中找不到项目,如何重定向到另一个页面?

php - GeSHi 网络代码编辑器

PHP MySQL 数据插入不起作用

c# - 如何在普通 htmlElement 的 onClick 事件上为 asp.net 中的 Session 设置一个值?

c# - NHibernate session 管理?

java - Tomcat servlet 中的 ThreadLocal

android - com.android.org.conscrypt.OpenSSLX509Certificate 无法转换为 java.security.Certificate

wcf - 访问仅启用 TLS 1.2 的服务器上运行的 WCF 服务