标题重定向后PHP $ _SESSION为空 [英] PHP $_SESSION empty after header redirect
本文介绍了标题重定向后PHP $ _SESSION为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我执行标头重定向时,我正在丢失$ _SESSION中的数据。当我使用调试器浏览时,我可以在退出前看到$ _SESSION中的所有数据();
$ b Login.php:
...
if($ result == 1){em>
header(Location:/myaccount.php);
session_write_close();
exit();
} else {
header(Location:/login.php?invalid=yes);
exit();
}
然后我在session_start()条件下面放置一个断点,$ _SESSION为完全空虚。
myaccount.php:
<?php
if(!isset($ _ SESSION ['user_id'])){session_start(); }
$ docRoot = getenv(DOCUMENT_ROOT);
...
我的会话去了哪里?
确保在<$ c的if语句之前使用函数
session_start();
$ c> myaccount.php I'm losing the data in $_SESSION when I do a header redirect. When I walk through this with a debugger I can see all my data in $_SESSION before I exit();
Login.php :
...
if($result == 1){
header("Location: /myaccount.php");
session_write_close();
exit();
} else {
header("Location: /login.php?invalid=yes");
exit();
}
Then I put a breakpoint after the session_start() conditional below and $_SESSION is completely empty.
myaccount.php:
<?php
if(!isset($_SESSION['user_id'])) { session_start(); }
$docRoot = getenv("DOCUMENT_ROOT");
...
Where did my session go?
解决方案
Make sure you are using the function session_start();
before the if-statement on myaccount.php
这篇关于标题重定向后PHP $ _SESSION为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文