dqc42632 2012-03-08 09:03
浏览 9
已采纳

在php注销什么更好?

i am having a debate on what would be a better method for loging out in php , if someone could help me clarify i would be most gratefull :

I have two versions of the code for log out

1 )

$logoutGoTo = "login.php";
if (!isset($_SESSION)) {
  session_start();
}
$_SESSION['username'] = NULL;
$_SESSION['user_id'] = NULL;
unset($_SESSION['username']);
unset($_SESSION['user_id']);
$_SESSION = array();
if ($logoutGoTo != "") {header("Location: $logoutGoTo");
exit;

2)

session_start();
    session_unset();
session_destroy();

Which is the better solution?

  • 写回答

3条回答 默认 最新

  • dqunzip3183 2012-03-08 09:10
    关注

    Generally neither because they both essentially destroy the entire session.

    Sessions aren't just for keeping user's logged in. Sessions are used to track other data which may not be linked to a user's account and so you might not want to destroy it when logging out.

    Take this for example, you store the language setting in the session. Now the user logs out, you want to keep language setting but logout the user. If you destroy the session then all other data your tracking is destroyed.

    I would simply unset/remove the session variables that are keeping the user logged in.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果