You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

主域名与子域名间Session丢失及重定向问题求助

主域与子域Session共享问题

我的网站主域https://www.progressiveai.org和子域https://auth.progressiveai.org存在Session管理问题:用户在auth子域完成登录后,访问主域的https://www.progressiveai.org/Talk页面时,会被重定向回auth子域,表现得像未登录状态。尝试清除浏览器Cookie和站点数据后问题依旧,但在隐身模式下操作一切正常。

主域Talk页面代码

<?php
session_start();
if (!isset($_SESSION['SESSION_EMAIL'])) {
    header("Location: https://auth.progressiveai.org");
    die();
}

include '../config.php';

$email = $_SESSION['SESSION_EMAIL'];

// Create a prepared statement
$stmt = mysqli_prepare($conn, "SELECT * FROM members WHERE email = ?");
if ($stmt === false) {
    die("Error: " . mysqli_error($conn));
}

// Bind the email parameter to the statement
mysqli_stmt_bind_param($stmt, "s", $email);

// Execute the statement
mysqli_stmt_execute($stmt);

// Get the result set
$result = mysqli_stmt_get_result($stmt);

if ($result) {
    // Fetch a single row as an associative array
    $row = mysqli_fetch_assoc($result);
    mysqli_free_result($result);
}

mysqli_stmt_close($stmt);
?>

auth子域相关代码

ini_set('session.cookie_domain', '.progressiveai.org');
session_start();

if (isset($_SESSION['SESSION_EMAIL'])) {
    header("Location: https://auth.progressiveai.org/redirect");
    die();
}

// Include your database configuration file
include '../config.php';

// Replace this query with your actual database query
$stmt = mysqli_prepare($conn, "SELECT * FROM users WHERE email = ?");
if ($stmt === false) {
    die("Error: " . mysqli_error($conn));
}

$email = ''; // Initialize email variable

// Bind the email parameter to the statement
mysqli_stmt_bind_param($stmt, "s", $email);

// Execute the statement
mysqli_stmt_execute($stmt);

// Get the result set
$result = mysqli_stmt_get_result($stmt);

if ($result) {
    // Fetch a single row as an associative array
    $row = mysqli_fetch_assoc($result);
    mysqli_free_result($result);
}

mysqli_stmt_close($stmt);

?>
...

我已经查阅过Stack Overflow上关于Session共享的相关文章,但文中提供的方案都无法解决这个问题,恳请技术支持。

内容的提问来源于stack exchange,提问作者Illanser

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 10:52:40