PHP Simple Logout Script
This is quietly simply logout script for your member that already login, by using php session_destroy function if you start login processed with session_start. Of course you can adding more function after session_destroy.
Here are the basic simply code, write and save as php file (ie; logout.php):
Want adding some message or redirect you can adding after session_destroy.
Message After Logout:
<?php
session_start();
session_destroy();
echo "put whatever your message here, you can using html code here";
?>
session_start();
session_destroy();
echo "put whatever your message here, you can using html code here";
?>
Redirect After Logout:
<?php
session_start();
session_destroy();
//you can change index.php with any url
header( ‘Location: index.php’ ) ;
?>
session_start();
session_destroy();
//you can change index.php with any url
header( ‘Location: index.php’ ) ;
?>
Related posts:
Tweet! This









So well and good posting. i liked it. keep going.
http://www.webroyalty.com
Great blog. I bookmarked your site. Th etip on php logout was also good enough.
Great blog. I bookmarked your site.PHP is now popular.Do you have any more about PHP?
Here I can show some to you: http://www.topnflnews.com
I opine that it is workable to see this web page, because here only scholars should notice the superb outcome associated with this post. Therefore, the dissertation writing service could use it for thesis titles accomplishing.
Got this code running! Thanks for your help. You have a lot of things useful here. I’m sure a lot of people will appreciate the help you’ve been doing so far. Kudos to you and more power to your blog.
Hmmm. the simple logout script seems very useful and you blog is cracking me out. It has lot of info for me.
Right now the simple script will logout all users if no acitivty is detected for a certain amount of time. I want this to work with the exception of a certain user.
This means that the next person to use the PC can access the website without a login because the last user is still logged in..
@ads Company:
I think it should put on member / restricted page to limiting login time. You can using time function for that purpose, ie; (put this after session start)
$current = time();
//then we decided how long the limit, 60s X 30
$limit = $current – 60 * 30;
//this is for check how long last user activity
if (isset ($_SESSION['last_activity']) &&
$_SESSION['last_activity'] < $limit) {
//now the rule of limit time will work and redirect if time limit expired
$_SESSION = array();
header('Location: http://yoursite/logout.php‘);
exit;
} else {
//But if time not yet expired, then user will still logged in
$_SESSION['last_activity'] = $current;
Yes ! I did simple
Thanks for this tutorial. This is great, another learning for me.
Thanks for the tip on how to create a logout script. But i was wondering if you had any advice on creating an entire user management system where users can log in and out, comment, etc? I know i can do it with WordPress, but i would rather not got that route for now.