PHP结束会话(不同的方式)我不明白 [英] PHP ending sessions(different ways) i dont understand

查看:77
本文介绍了PHP结束会话(不同的方式)我不明白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解会议以及结束会议的某些功能如何工作. 我去过不同的站点,甚至在这里也是如此,从本质上讲,什么都没用.

I'm trying to understand sessions and how some of the functions to end them work. I've gone to different sites/and even here on SO and, well essentially, nothing is working.

我有一个正在尝试使用的应用,当用户登录时,我会像这样存储用户名 (不会粘贴整个代码,但您会明白)

I have an app I'm trying to work on and when the user logs in, I store the username like so (not going to paste the whole code but you get the idea)

if($row == 1){
    session_start();
    $_SESSION['usrname'] = $login_usrname;
    $_SESSION['usrpass'] = $login_usrpass;
    header("Location:index.php");
    exit;
}

在所述应用的索引页面上,我像这样进行支票

On the index page of said app I have a check like so

session_start();
if(!isset($_SESSION['usrname']) && !isset($_SESSION['usrpass'])){ 
    header("Location:login-acc.php");
    exit;
}

它允许它们进入.我在firefoxes Web开发工具中检查了cookie,然后看到它正在生成,因此到目前为止,我要说它正在工作".

And it lets them in. I check the cookies in firefoxes web dev tools and I see it being generated so I'm going to say "its working" so far.

现在,当我要注销时,长话短说,我有一个注销链接,该链接将其带到应该清除所有会话数据并将其重定向到登录页面的页面.当我测试应用程序并单击注销链接时,我将重定向到登录页面,但是当我返回并单击索引页面"链接时.它可以让我直接进入.

Now when I want to log out, Long story short I have a logout link that takes them to a page that's supposed to clear all session data and redirect them to the login page. When I'm testing the app and I click the logout link, I get redirected to the login page but when i go back and click the "index page" link. it lets me right in.

在登出文件中,尝试强制在过度杀伤大声笑中的问题,我知道了这一点,而且似乎无济于事.

In the logout file, trying to FORCE the issue in overkill lol, I have this and nothing seems to work.

unset($_SESSION['usrname']);
unset($_SESSION['usrpass']);

session_unset();

$_SESSION = array();
session_destroy();

setcookie('PHPSESSID', '', time()-3600,'/', '', 0, 0);

header("Location:login-acc.php");
exit;

它将我重定向到登录页面,但是再次,当我手动进入索引页面时,它可以让我直接进入.或者在重定向到登录页面后,我单击后退"按钮,也可以让我直接进入.

It redirects me to the login page but again, when I manually go to index page it lets me right in. Or after being redirected to the login page, I hit the "back" button and lets me right in as well.

如果我随后进入FF Web开发人员工具应用程序并删除所有cookie等,然后导航到索引页面,则会将我拒之门外.

If I then go into FF Web developer tools app and delete all cookies etc, and navigate to the index page, then it locks me out.

正如您在上面看到的,我尝试了多种方法,最后,我将它们全部组合在一起,应该可以做一些事情.我的问题是,由于我已放入所有这些功能来尝试在整个会话中进行尝试/删除/取消设置/删除操作,我还能做什么?我对它的工作方式有些迷惑.

As you can see above ive tried multiple things and in the end, I threw them all together which should do something. My question is since I've put in ALL those functions to try and delete/unset/remove in general the session, what else can I do? I'm a bit lost as to how its supposed to work.

有人可以指引我正确的方向吗?

Can someone steer me in the right direction?

推荐答案

注销页面顶部缺少session_start().它正在尝试修改不存在的会话!

You are missing a session_start() at the top of your logout page. It's trying to modify a session that doesn't exist!

这篇关于PHP结束会话(不同的方式)我不明白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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