4. Logout session and cookie page: logOut.php (redirect to lonIn.php after logout)
Copy code
The code is as follows:
/**Log out the session and cookie pages at the same time*/
//Even when logging out, you must start a session first to access session variables
session_start();
//Use a session variable to check login status
if(isset($_SESSION['user_id'])){
//To clear the session variable, set the $_SESSION super global variable to an empty array
$_SESSION = array();
//If there is a session cookie, delete it by setting the expiration time to 1 hour before
if(isset($_COOKIE[session_name()])){
setcookie(session_name(),'',time()-3600);
}
//Use the built-in session_destroy() function to call to cancel the session
session_destroy();
}
//At the same time, set the expiration time of each cookie to a time in the past so that they will be deleted by the system. The time is in seconds
setcookie('user_id','',time()-3600);
setcookie('username','',time()-3600);
//The location header causes the browser to redirect to another page
$home_url = 'logIn.php';
header ('Location:'.$home_url);
?>
http://www.bkjia.com/PHPjc/328072.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328072.htmlTechArticleUse session and cookie at the same time to save user login information 1. Database connection configuration page: connectvars.php Copy the code as follows : ?php //Database location define('DB_HOST', '127...