end session and reload page from within logout function?

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

Post Reply
sjk1000
Forum Commoner
Posts: 26
Joined: Tue Nov 11, 2008 8:50 am

end session and reload page from within logout function?

Post by sjk1000 »

Hi all
I've a logout button that runs a function to destroy the session and then return to the same page. The location of the logout function within the script means that on the button click the user doesn't return to login prompt as I'd like. A page reload at this point instantly deals with it. I'd rather not rework the flow of the script because this is the last thing I'm doing on the page. How do I force the browser to reload the page from within the logout function?
Thanks, Steve
dark_religion
Forum Newbie
Posts: 3
Joined: Sat Dec 06, 2008 3:00 am

Re: end session and reload page from within logout function?

Post by dark_religion »

did you try header("Location: http://domain/login.php") ?
sjk1000
Forum Commoner
Posts: 26
Joined: Tue Nov 11, 2008 8:50 am

Re: end session and reload page from within logout function?

Post by sjk1000 »

OK I've solved the problem but I don't understand how. I did it by calling the seller_logout function from within itself which has a similar effect to refreshing the page - [insert mixed emotions smiley here]. Can someone explain why this works? Thanks

Code: Select all

<?php
function seller_logout()
{
unset($_SESSION['valid_user']);
session_destroy();
seller_logout ();
}
?>
sjk1000
Forum Commoner
Posts: 26
Joined: Tue Nov 11, 2008 8:50 am

Re: end session and reload page from within logout function?

Post by sjk1000 »

ps thanks for your reply dark_religion. I mucked around for a while trying to figure out where I was supposed to put it in the function with no success. If I hadn't found the weird workaround above, where would it go?
Thanks, Steve
Post Reply