英文:
How to completely end a session in PHP after clicking Logout?
问题
现在我有一个网站,当我点击退出按钮时,它会将我重定向到登录页面,但如果我更改浏览器的URL为menu.php,例如,我发现用户仍然在线,我不知道如何完全终止会话。
退出按钮将用户重定向到logout.php,其中包含以下代码
<?php
session_unset();
session_destroy();
header("Location: index.php");
exit();
?>
我当时在menu.php页面,然后点击了退出按钮。它将我重定向到了index.php,就像应该的那样。但当我将浏览器的URL从index.php更改为menu.php时,我发现欢迎消息中仍然包含上一个用户名!
menu.php应该在您点击退出后不打开,除非您再次登录。
英文:
Now I have a website , when I press log out button it return me to the login page, but if I change the url of the browser to menu.php for an example, I found the user is still on , I don't know how do I kill the session completely .
logout button will direct the user to logout.php which has the following code
<?php
session_unset();
session_destroy();
header("Location: index.php");
exit();
?>
I was in menu.php and I click on Logout button. It direceted me to index.php as it's suppose to be. When I changed the url of the browser from index.php to menu.php I found the welcome message containing the last user name in!
menu.php suppose to not open if you click logout and did not sign in again
答案1
得分: 0
我终于找到了。
说我必须在结束会话之前开始会话的那个人是对的。
这是新的logout.php代码:
<?php
session_start();
session_unset();
session_destroy();
header("Location: index.php");
?>
英文:
I finally found it out.
The guy who said that I must start the session before I end it was right
this is the new logout.php code
<?php
session_start();
session_unset();
session_destroy();
header("Location: index.php");
?>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论