Home > Backend Development > PHP Problem > How to click to log out after php login?

How to click to log out after php login?

Release: 2023-02-27 16:10:01
Original
4749 people have browsed it

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. .

How to click to log out after php login?

php After logging in, click to log out. Implementation code:

<?php
$_SESSION = array(); //清除SESSION值.
    if(isset($_COOKIE[session_name()])){  //判断客户端的cookie文件是否存在,存在的话将其设置为过期.
    setcookie(session_name(),&#39;&#39;,time()-1,&#39;/&#39;);
    }
    session_destroy();  //清除服务器的sesion文件

echo "<script>location.href=&#39;index.php&#39;;</script>";
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template