Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

How to use logout script

General discussions related to php

Moderators: macek, egami, gesf

How to use logout script

Postby phpkiller » Fri Mar 22, 2013 4:05 am

Create a link or button for logout and below is the logout script:

<a href="logout.php">Logout</a>


logout.php:

<?PHP

session_start();
session_destroy();

?>
phpkiller
New php-forum User
New php-forum User
 
Posts: 31
Joined: Thu Jun 28, 2012 2:11 pm

Re: How to use logout script

Postby johnj » Mon Mar 25, 2013 5:44 am

reset any other variables (if necessary) and then do a page redirect.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: How to use logout script

Postby seandisanti » Thu Mar 28, 2013 10:54 pm

johnj wrote:reset any other variables (if necessary) and then do a page redirect.

and if you are using cookies, make sure to expire them by setting their expiration time to a negative number.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: How to use logout script

Postby Crabbpower » Fri Mar 29, 2013 1:06 am

This is how I like to do it, you start session make it into an empty array then expire cookie by any minus and last destroy the session.

Code: Select all
<php?
session_start();

$_SESSION = array();

if(isset($_COKKIE[session_name()])) {
   setcookie(session_name(), '', time()-10000, '/');
}

session_destroy();
?>
Crabbpower
New php-forum User
New php-forum User
 
Posts: 5
Joined: Thu Mar 28, 2013 2:05 pm

Re: How to use logout script

Postby seandisanti » Fri Mar 29, 2013 7:12 am

and you can even modularize all of that into a session object that you can reuse in other code. here's a video example http://jream.com/learning/videos/php-oo ... on-wrapper
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP General

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron