INeedAGig Posted March 31, 2011 Share Posted March 31, 2011 Hey guys, me again. A few of you were helping me with my login script, which I did finally get working. I am having one small problem though. Upon clicking the logout link, it does not re-direct back to the login page, it just stays blank. I have pasted my code from my logout.php file for reference. Thanks in advance for your help! Logout.php code <?php session_start(); session_destroy(); { header("location: login.php"); } exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/232333-logout-not-re-directing/ Share on other sites More sharing options...
garrypeace Posted March 31, 2011 Share Posted March 31, 2011 <?php session_start(); session_destroy(); header("location: login.php"); exit(); ?> You don't need the braces. Also make sure this is placed before any data is sent to the headers, i.e. before anything. Right at the top of the page. Quote Link to comment https://forums.phpfreaks.com/topic/232333-logout-not-re-directing/#findComment-1195205 Share on other sites More sharing options...
INeedAGig Posted March 31, 2011 Author Share Posted March 31, 2011 Yeah, this is the entire code of my logout.php file. I removed the bracers but it is still staying on a blank page for some reason.... Quote Link to comment https://forums.phpfreaks.com/topic/232333-logout-not-re-directing/#findComment-1195210 Share on other sites More sharing options...
INeedAGig Posted March 31, 2011 Author Share Posted March 31, 2011 Okay, its working now...I changed the header to an include, but is this still correct? <?php session_start(); session_destroy(); include "login.php"; exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/232333-logout-not-re-directing/#findComment-1195211 Share on other sites More sharing options...
garrypeace Posted March 31, 2011 Share Posted March 31, 2011 Try replacing exit() with session_close() but keeping the header() instead of an include. Quote Link to comment https://forums.phpfreaks.com/topic/232333-logout-not-re-directing/#findComment-1195212 Share on other sites More sharing options...
INeedAGig Posted March 31, 2011 Author Share Posted March 31, 2011 Okay, I tried your suggestion and changed the code to <?php session_start(); session_destroy(); header ("location: login.php"); session_close(); ?> This results in the following error: Fatal error: Call to undefined function: session_close() in logout.php on line 5 Quote Link to comment https://forums.phpfreaks.com/topic/232333-logout-not-re-directing/#findComment-1195214 Share on other sites More sharing options...
garrypeace Posted March 31, 2011 Share Posted March 31, 2011 Okay, I tried your suggestion and changed the code to <?php session_start(); session_destroy(); header ("location: login.php"); session_close(); ?> This results in the following error: Fatal error: Call to undefined function: session_close() in logout.php on line 5 Sorry, I meant session_write_close(). Try it without an exit() or close. If that doesn't work, I'm just being stupid and someone else will point it out Quote Link to comment https://forums.phpfreaks.com/topic/232333-logout-not-re-directing/#findComment-1195216 Share on other sites More sharing options...
INeedAGig Posted March 31, 2011 Author Share Posted March 31, 2011 Nope, just a blank page. Is it okay to do it with an include, or is that incorrect? It worked using an include, hehe. Quote Link to comment https://forums.phpfreaks.com/topic/232333-logout-not-re-directing/#findComment-1195218 Share on other sites More sharing options...
PFMaBiSmAd Posted March 31, 2011 Share Posted March 31, 2011 You apparently have a blank line before the <?php tag. That is output that is sent to the browser and will produce a header() error. At the risk of being repetitive, someone has previously suggested to you to set error_reporting to E_ALL and display_errors to on so that php will help you when you are developing and debugging your code. You will save a TON of time. Quote Link to comment https://forums.phpfreaks.com/topic/232333-logout-not-re-directing/#findComment-1195230 Share on other sites More sharing options...
INeedAGig Posted March 31, 2011 Author Share Posted March 31, 2011 Solved...it was a BOM causing it to error. Quote Link to comment https://forums.phpfreaks.com/topic/232333-logout-not-re-directing/#findComment-1195271 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.