PHP会话似乎不工作 [英] PHP session seemingly not working

查看:115
本文介绍了PHP会话似乎不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

会话变量显然不适合我。我不知道我做错了什么。这是我用来检查有效密码的代码:

Session variables are apparently not working for me. I don't know what I'm doing wrong. This is the code that I'm using to check for a valid password:

if ($input_password_hash == $password_hash)
 {
  session_start();
  $_SESSION['is_user'] = 1;
  header("Location: ../new_look"); //or Location: index.php
 }
else echo "Wrong password.";

在index.php文件(重定向到),我有这样的代码:

in the index.php file (where it redirects to), I have this code:

if ($_SESSION['is_user'] == 1)
{
  //show index page with navigation bar for registered user
}

else
{
 //do something else
}

但它根本不工作。

会话显然开始,可以通过检查

The session does apparently start and that can be verified by checking the cookie.

我做错了什么?

推荐答案

在任何请求中使用 $ _ SESSION 变量之前,您必须编写 session_start()看起来你没有把它放在index.php的任何地方。

You know that you've got to write session_start() before you use the $_SESSION variable in any request, right? It looks like you haven't put it in index.php anywhere.

这篇关于PHP会话似乎不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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