FW: PHP Logout

A good logout script is needed in most applications, and here’s the one I use. I have this script in a ‘config’ file that I call at the beginning of...

A good logout script is needed in most applications, and here’s the one I use. I have this script in a ‘config’ file that I call at the beginning of every file in the site, so you can logout from any page…

if(isset($_GET['logout'])){ // trigger if ?logout is in the url
	$_SESSION = array();
	if(isset($_COOKIE[session_name()])){
   		setcookie(session_name(), '', time()-42000, '/');
	}
	session_destroy();
	header ('location: /'); // redirect to root
	exit();
}

To trigger it, simply add ‘?logout‘ after a url path, i.e. www.mydomain.com/?logout.

Related posts:

  1. Delete Sessions
  2. Check if user is ‘logged in’ or is ‘admin’
  3. Redirect Page
  4. Handling File Downloads with PHP
  5. Connect To Database With mysqli_connect

This post has had 8 views