PHP - 登录脚本不创建会话 [英] PHP - Log in Script Not Creating Sessions

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

问题描述

我有一个登录脚本,可以在其中成功创建用户并登录.现在我的问题是,每当我尝试使用我的页面保护方法时,都会查看用户"是否有会话如果不是,它会将您引导回登录页面.

I have a log in script where I have been able to successfully make users, and log in. Now my issue is that whenever I try to use my method of protecting pages, being seeing if there is a SESSION for 'user' if not it directs you back to the login page.

这是我检查会话,

require("common.php"); 


if(empty($_SESSION['user'])) 
{ 

    header("Location: login"); 

    die("Redirecting to login"); 
} 

这里是我设置会话的地方,我只设置一个 session_start();在登录.php

Here is where I am setting my session, I am ONLY setting a session_start(); on login.php

if($login_ok) 
    { 

        unset($row['salt']); 
        unset($row['password']); 

        $_SESSION['user'] = $row; 

        header("Location: home?worked=1"); 
        die("Redirecting to: home?worked=1");
        session_start(); 
    } 
    else 
    { 
        print("Login Failed."); 
        $submitted_username = htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8'); 
    } 
} 

这是做什么的,是我登录,它会处理并将我带到我的主页,然后将标题处理回登录页面,就像我没有登录一样.我测试了一个错误登录,它是告诉它是正确的登录.

What this does, is I log in, and it will process and bring me to my home page, then process the header back to the login page acting as if I am not logged in. I tested a false login and it IS telling that its the correct login.

感谢您的帮助,我正在这里拔头发!

Thanks for any help, I'm pulling my hair out here!

死灵

编辑

我移动了 session_start();到我的 common.php 顶部,一切都很完美.

I moved session_start(); to the top of my common.php, and everything is perfect.

推荐答案

你需要把 session_start();在您要使用会话的每个页面上.

You need to put session_start(); on every page you want to use the session.

这篇关于PHP - 登录脚本不创建会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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