我已经阅读了很多关于注销脚本的php教程,我想知道什么是从会话注销的正确方法!
脚本1
<?php
session_start();
session_destroy();
header("location:index.php");
?>
Run Code Online (Sandbox Code Playgroud)
脚本2
<?php
session_start();
session_unset();
session_destroy();
header("location:index.php");
?>
Run Code Online (Sandbox Code Playgroud)
脚本3
<?php
session_start();
if (isset($_SESSION['username']))
{
unset($_SESSION['username']);
}
header("location:index.php");
?>
Run Code Online (Sandbox Code Playgroud)
有没有更有效的方法来做到这一点?可以通过重新登录来创建会话,所以我是否应该使用session_destroy()并使用unset($ _ SESSION ['variable'])来代替?上面哪3个脚本更优选?