Every time you jump to a page, first determine whether the session exists. If the session does not exist, jump to the login page. After logging in, save the session. If there is a session, continue the operation. If you click to log out, clear the session first, and then jump to the login interface. .
php After logging in, click to log out. Implementation code:
<?php $_SESSION = array(); //清除SESSION值. if(isset($_COOKIE[session_name()])){ //判断客户端的cookie文件是否存在,存在的话将其设置为过期. setcookie(session_name(),'',time()-1,'/'); } session_destroy(); //清除服务器的sesion文件 echo "<script>location.href='index.php';</script>"; ?>
session variables are used to store information about the user session (session), or change User session settings. Session variables store information for a single user and are available to all pages in the application.
If you want to delete some session data, you can use the unset() or session_destroy() function.
Recommended reading: php server
The above is the detailed content of How to click to log out after php login?. For more information, please follow other related articles on the PHP Chinese website!