Need Help with Sessions Please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

The sign out (or logout) routine typically involves click origination. What that means is that a user clicks a link/button and then is taken to a page that handles logouts and session destruction. Closing a session should not happen automatically unless your allowable logged in time limit is reached.
User avatar
boo_lolly
Forum Contributor
Posts: 154
Joined: Tue Nov 14, 2006 5:04 pm

Post by boo_lolly »

write a redirect page. when the user clicks <span><a href="redirect.php">Sign Out</a></span>

the redirect page will look something like...

Code: Select all

<?php
//redirect.php

     signOut();
     header("Location: http://www.yoursite.com/youareloggedout.php");

?>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

So that would be two redirects?

Why not post back to the calling page with a querystring trigger?

Code: Select all

<?php
if (isset($_GET['logout']) && $_GET['logout'] == 'true')
{
    session_destroy();
    // Do whatever else you want to do on a logout
}

echo '<a href="' . basename($_SERVER['SCRIPT_FILENAME']) . '" title="Logout">Click here to logout</a>';
?>
Post Reply