重定向时丢失$ _SESSION []的值

时间:2010-07-04 19:26:33

标签: php session

我有一个问题,无论如何都无法解决。

我有三个文件 - index.phpadmin.phppost.php

index.php我有

<?
session_start();
$_SESSION['login11_error'] = 'yes';
if(verifying username and password here, if they correct)
{
     $_SESSION['login11_error'] = 'no';
     header('Location: admin.php');
}
?>

admin.php我有

<?
session_start();
<form action="post.php" method="post">
...
?>

最后在post.php

<?
session_start();
some functions here...
header("location:admin.php");
?>

但是当它从admin.php重定向到post.php时,会失去$_SESSION['login11_error']的值。

任何想法?

...谢谢

更新

固定。

因为我只是在这里展示了脚本的结构,所以我的问题出了问题。

发布php在另一个文件夹中,然后是index.php和admin.php,它位于/folder1/folder1_1/post.php

在post.php中我写了header('Location: http://bs.am/admin.php")

当我将其更改为header('Location: ../../admin.php")时,它就开始工作了。

对我来说难以理解的行为,但有效:)

3 个答案:

答案 0 :(得分:2)

Syom,

我没有看到您的示例代码有任何明显错误。

如果从index.php到admin.php的重定向工作(持久化你的会话变量),那么post.php中肯定会发生一些棘手的事情。你能在post.php中注释掉你的所有代码,只需重定向到admin.php吗?也就是说,post.php只包含:

<?
header('Location: admin.php');
?>

如果echo $_SESSION['login11_error'];(在admin_php中,当然是在start_session()之后)打印了一些内容,请在post.php中取消注释项目。

如果您处于静止状态,请复制http://www.php.net/manual/en/function.session-start.php中的示例,并确保它适合您。

答案 1 :(得分:1)

答案 2 :(得分:0)

尝试在每session_name('MySESS');

之前手动设置session_start()