Jump to content

How to refresh page after logging out


Mal1

Recommended Posts

I've got login script which seems to be working as I want if apart from when you log out. It is logging out fine but I've made a button at the top of the site which says login (if no session is logged in) or logout (if they are logged in).

 

On logging out this button doesn't change until you go to another page or refresh the browser.

 

Is there a way of forcing a refresh or is there something else I should be doing?

 

Logout code here:

 

<?
if(!isset($_REQUEST['logmeout'])){
echo "<center>Are you sure you want to logout?</center><br />";
echo "<center><a href=logout.php?logmeout>Yes</a> | <a href=javascript:history.back()>No</a>";
} else {
session_destroy();
if(!session_is_registered('first_name')){
 echo "<center><font color=red><strong>You are now logged out!</strong></font></center><br />";
 echo "<center><strong>Login:</strong></center><br />";
 include 'login_form.html';
}
}
?>

 

 

Code I'm using in my header.php is:

 

<? if (isset($_SESSION['first_name']))
{
include $_SERVER['DOCUMENT_ROOT'] .  '/layout/logout.php';
}
else
include $_SERVER['DOCUMENT_ROOT'] . '/layout/signin.php';
?>

Link to comment
Share on other sites

header('Location: url here');

 

I've tried header in the past (unless I'm using it the wrong way or putting it in the wrong place) I'm getting:

 

Warning: Cannot modify header information - headers already sent by (output started at /homepages/33/d440142155/htdocs/LuxuryLiving/member/logout.php:12) in /homepages/33/d440142155/htdocs/LuxuryLiving/member/logout.php on line 33

Link to comment
Share on other sites

Actually, the sticky has been unstickied. Though, it still linked to (and answered) in the FAQ.

So, yeah: Always read the FAQ, Mal1.

 

I've read that FAQ as I had the same issues at the start when adding the login/logout switch but didn't want to put ob start on every single page as it's surely not the correct way to do things. In this case as it's just one page it worked - although I had to create a new page to redirect to as it didn't work the same way loading the same page with new text.

Link to comment
Share on other sites

Don't use ob, fix your script so you do all the logic before outputting anything. I don't get why people read posts like those and only look for the "quick fix". It tells you how to fix it.

http://forums.phpfreaks.com/topic/273121-readme-php-resources-faqs/page__p__1405508#entry1405508

http://forums.phpfreaks.com/topic/1895-header-errors-read-here-before-posting-them/

Link to comment
Share on other sites

Don't use ob, fix your script so you do all the logic before outputting anything. I don't get why people read posts like those and only look for the "quick fix". It tells you how to fix it.

http://forums.phpfre...08#entry1405508

http://forums.phpfre...e-posting-them/

 

For a complete novice it's not as easy as saying "fix the logic" when you don't know what's wrong with it or how to fix it. The "put the processing in the header, and store the results in variables. perhaps a $result variable that is 1 if successful, 0 if failed. then $output that contains either a success message or customized error messages." doesn't really make sense to me either...

 

Anyway... I've removed the ob start and put:

 

<?
session_start();
if(isset($_REQUEST['logmeout'])){
session_destroy();
header('Location: logoutsuccess.php');
}
?>

 

At the top of the page and echo'd what's to be said down within the content and it seems to be working. Hopefully that's it fixed without just band-aiding the problem?

Link to comment
Share on other sites

You will also need to use die () after sending a header () redirect, otherwise PHP will continue to parse your script. Something which may very well cause errors, or security issues.

 

Thanks... should that just go directly after header () redirect?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.