View Full Version : logout page refresh to itself.

01-02-2008, 02:01 PM
i am trying to get the page to revisit itself one the members is logged out, but on refresh it will not try to log them out as they will not be online anymore due to the $user = NULL so the refresh will only run once, but it does not even run the once due to the headers already being sent.

<?php // this file is logout.php
if ($user) {
$res = mysql_query("UPDATE `membersonline` SET `status` = 'LOGGEDOUT' WHERE `user` = '".$user."' LIMIT 1") or die(mysql_error());
$user = "";

// the rest works but the next line
header ("Refresh: 0; URL=http://site.com/logout.php");

<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>
<p align="center">You are no longer logged in.</p>
<p align="center">Thank you for visiting <?=$sitename;?></p>
<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>

01-02-2008, 02:13 PM
Though I didn't get your requirement completely, the php header() (http://us2.php.net/header) functions requires to be called before any actual output is sent (ie there shoudn't be any echo/print statements or html before this)
See the manual.

01-02-2008, 02:21 PM
i know that but it is an example of what i was trying to do.

how can i get the page to refresh/revisit.

obviously it will not repeat this process again as the member will have been logged out the first time.

01-02-2008, 04:07 PM
You could use a meta refresh (http://en.wikipedia.org/wiki/Meta_refresh), but if you process the logout before the page is loaded you won't need to reload it; just show the appropriate content. Keep in mind that $user by itself will not persist across pageloads. You'll have to use a $_SESSION or $_COOKIE for that.

01-02-2008, 08:25 PM
What about...

if($user == NULL) {

} else {
// Logout Code