【问题标题】:header redirect $_SESSION empty标头重定向 $_SESSION 为空
【发布时间】:2013-06-12 13:35:00
【问题描述】:

我有以下脚本: 登录.php

 session_start();
    #login procedure (not relevant)
    if (login(..)) {
        $_SESSION['uid'] = $foo;
        $_SESSION['login'] = true;

        session_write_close();

        var_dump($_SESSION); //=> works properly

        header('location: index.php');
        exit();
    }

index.php

session_start();
include( 'core/auth.php');

//..

auth.php

session_start();
var_dump($_SESSION); //=> EMPTY (!)

所以看起来会话变量在重定向期间丢失了。 是服务器配置问题吗?

任何帮助表示赞赏。

【问题讨论】:

  • 你是在本地主机上运行这个吗?
  • 为什么双 session_start() 调用不会产生错误?
  • if ( ! session_id()) session_start();core/auth.php中使用它
  • @Dale 不知道。我用你的代码替换了它。
  • 突然间它起作用了。谢谢!估计是服务器问题..

标签: php session redirect location


【解决方案1】:

如果您使用“文件”作为 PHP 会话保存处理程序(session.save_handler php.ini 中的变量),请检查托管 PHP 进程的用户(可能是 apache 或 nginx)对保存路径有写权限。(session.save_path)

【讨论】:

    猜你喜欢
    • 2011-07-01
    • 2016-06-20
    • 1970-01-01
    • 1970-01-01
    • 2013-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多