页面之间的会话消失了 [英] session wiped out between pages

查看:52
本文介绍了页面之间的会话消失了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个登录页面,但由于某种原因,会话不会在我设置它的位置和我转发到的页面之间持续存在.我可以在会话初始化的页面中注释掉标题,并查看会话中是否包含数据.但是,当我在目标页面中执行 print_r 时,会话为空.

I'm making a login page and for some reason the session will not persist between where I set it and the page where I am forwarding to. I can comment out the header in the page where the session was initialized and see that the session has the data in it. However, when I do a print_r in the target page, the session is empty.

我已经确定调用了 session_start.此站点只有一个域,我的浏览器设置为接受 cookie.我可以转发到任何其他页面并查看会话数据,但不能转发到这个页面.

I have already made sure that session_start is called. There is only one domain for this site and my browser is set to accept cookies. I can forward to any other page and see the session data but just not this one.

有人可以提供什么东西来帮助调试吗?

Is there something that someone can offer to help in debugging this?

$_SESSION['auth'] = $auth;
header( "Location: /" ); // commenting this out shows the data is in fact there

我想保护索引页,所以我测试看看 session['auth'] 是否设置.如果没有,我转发到/user/login 允许用户登录.如果成功,我们将返回到索引页面,它应该通过isset会话测试.但是它失败了并且没有会话数据.

I want to protect the index page so I test to see if session['auth'] is set. If not, I forward over to /user/login which allows the user to login. If successful then we forward back over to the index page where it should pass the isset session test. It fails though and there is no session data.

推荐答案

set.php:

session_start();
$_SESSION['auth'] = true;

header('Location: /');

index.php:

session_start();

var_dump($_SESSION);

创建这两个文件并请求 set.php.你看到了什么?

Create these 2 files and request set.php. What do you see?

这篇关于页面之间的会话消失了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆