Mal1 Posted January 21, 2013 Share Posted January 21, 2013 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'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/273424-how-to-refresh-page-after-logging-out/ Share on other sites More sharing options...
Jessica Posted January 21, 2013 Share Posted January 21, 2013 header('Location: url here'); Quote Link to comment https://forums.phpfreaks.com/topic/273424-how-to-refresh-page-after-logging-out/#findComment-1407246 Share on other sites More sharing options...
Mal1 Posted January 21, 2013 Author Share Posted January 21, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/273424-how-to-refresh-page-after-logging-out/#findComment-1407252 Share on other sites More sharing options...
Jessica Posted January 21, 2013 Share Posted January 21, 2013 There's a sticky about how to fix that problem. Quote Link to comment https://forums.phpfreaks.com/topic/273424-how-to-refresh-page-after-logging-out/#findComment-1407253 Share on other sites More sharing options...
Christian F. Posted January 21, 2013 Share Posted January 21, 2013 Actually, the sticky has been unstickied. Though, it still linked to (and answered) in the FAQ. So, yeah: Always read the FAQ, Mal1. Quote Link to comment https://forums.phpfreaks.com/topic/273424-how-to-refresh-page-after-logging-out/#findComment-1407255 Share on other sites More sharing options...
Mal1 Posted January 21, 2013 Author Share Posted January 21, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/273424-how-to-refresh-page-after-logging-out/#findComment-1407257 Share on other sites More sharing options...
Jessica Posted January 21, 2013 Share Posted January 21, 2013 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/ Quote Link to comment https://forums.phpfreaks.com/topic/273424-how-to-refresh-page-after-logging-out/#findComment-1407258 Share on other sites More sharing options...
Mal1 Posted January 21, 2013 Author Share Posted January 21, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/273424-how-to-refresh-page-after-logging-out/#findComment-1407262 Share on other sites More sharing options...
Jessica Posted January 21, 2013 Share Posted January 21, 2013 Anything that echos needs to be below anything that changes the header like a location redirect, session start, cookies, etc. Quote Link to comment https://forums.phpfreaks.com/topic/273424-how-to-refresh-page-after-logging-out/#findComment-1407263 Share on other sites More sharing options...
Christian F. Posted January 21, 2013 Share Posted January 21, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/273424-how-to-refresh-page-after-logging-out/#findComment-1407276 Share on other sites More sharing options...
Mal1 Posted January 21, 2013 Author Share Posted January 21, 2013 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? Quote Link to comment https://forums.phpfreaks.com/topic/273424-how-to-refresh-page-after-logging-out/#findComment-1407277 Share on other sites More sharing options...
Jessica Posted January 21, 2013 Share Posted January 21, 2013 yep! Always do die() right after a location redirect. Not all headers, just when you use location. Quote Link to comment https://forums.phpfreaks.com/topic/273424-how-to-refresh-page-after-logging-out/#findComment-1407281 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.