PHP:会话在标题重定向之前未保存 [英] PHP: session isn't saving before header redirect
问题描述
我已经阅读了这个问题的PHP手册,这似乎是一个很常见的问题,但我还没有找到解决方案。我将会话保存在数据库中。
我的代码如下:
// session
$ _SESSION ['userID'] = $用户>编号;
header('Location:/subdirectory/index.php');
然后在 编辑:我在我的文件顶部有session_start()。当我在页面重定向之前var_dump会话全局时,我看到了那里的用户标识,但没有在其他文件中,这是在这个脚本的子目录中 我知道这是一个旧的toppic,但我找到了解决方案(对我来说)。 这适用于我 I have read through the php manual for this problem and it seems quite a common issue but i have yet to find a solution. I am saving sessions in a database.
My code is as follows: Then at the top of index.php after the Edit: I have session_start() at the top of my file. When i var_dump the session global before the header redirect, i see the userID in there, but not in the other file, which is in a subdirectory of this script I know this is an old toppic but I found the solution (for me).
I've put a exit after the header. This works for me 这篇关于PHP:会话在标题重定向之前未保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! session_start()之后的index.php顶部, code>,我var_dumped $ _SESSION全局和用户ID不在那里。正如我所说的,通过PHP手册(
http://php.net/manual/en/function.session-write-close.php
)查看并且 session_write_close
或 session_regenerate_id(true)
为我工作。
有人知道解决方案吗?
我在标题后面放了一个退出。
$ _ SESSION ['session'] ='这是一个会议;
header('location:apage.php');
出口;
// session
$_SESSION['userID'] = $user->id;
header('Location: /subdirectory/index.php');
session_start()
, i have var_dumped the $_SESSION global and the userID is not in there. As i said ive looked through the PHP manual (http://php.net/manual/en/function.session-write-close.php
) and neither session_write_close
or session_regenerate_id(true)
worked for me.
Does anybody know a solution? $_SESSION['session'] = 'this is a session';
header('location: apage.php');
exit;