spacepoet Posted January 31, 2011 Share Posted January 31, 2011 Hi again: How do I do a proper log off link, to destroy the session from the initial login to the admin area, and then redirect the user back to the login page? I have a link called "Log Off" which goes to a page "a_LogOff.php" and this is the code: <? session_destroy(); header("location:Login.php"); ?> I am use to ASP and doing it this way: <% session.abandon response.redirect "Login.asp" %> Which works fine and is pretty easy. Doing it in PHP keeps giving me this error: Warning: session_destroy() [function.session-destroy]: Trying to destroy uninitialized session in /admin/a_LogOff.php on line 2 Warning: Cannot modify header information - headers already sent by (output started at admin/a_LogOff.php:2) in admin/a_LogOff.php on line 3 I thought this would be the easy part of the project, but apparently I am mistaken ... Anyone know how to do this? Link to comment https://forums.phpfreaks.com/topic/226194-how-do-i-do-a-log-off-link/ Share on other sites More sharing options...
trq Posted January 31, 2011 Share Posted January 31, 2011 You need to call session_start() prior to using any other session functions. Link to comment https://forums.phpfreaks.com/topic/226194-how-do-i-do-a-log-off-link/#findComment-1167685 Share on other sites More sharing options...
spacepoet Posted January 31, 2011 Author Share Posted January 31, 2011 Well, I had tried that. This is the original code for that: // Put this code in first line of web page. <? session_start(); session_destroy(); header("location:login.php"); ?> But I keep getting this error: // Put this code in first line of web page. Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /admin/a_LogOff.php:2) in /admin/a_LogOff.php on line 3 Warning: Cannot modify header information - headers already sent by (output started at /admin/a_LogOff.php:2) in /admin/a_LogOff.php on line 6 Any idea why? Link to comment https://forums.phpfreaks.com/topic/226194-how-do-i-do-a-log-off-link/#findComment-1167692 Share on other sites More sharing options...
suma237 Posted January 31, 2011 Share Posted January 31, 2011 remove the comment and also the space // Put this code in first line of web page. Link to comment https://forums.phpfreaks.com/topic/226194-how-do-i-do-a-log-off-link/#findComment-1167694 Share on other sites More sharing options...
trq Posted January 31, 2011 Share Posted January 31, 2011 Something must be sending output to the browser. There is a sticky in this board which covers the subject. Link to comment https://forums.phpfreaks.com/topic/226194-how-do-i-do-a-log-off-link/#findComment-1167695 Share on other sites More sharing options...
spacepoet Posted January 31, 2011 Author Share Posted January 31, 2011 Yes! Thanks. It was the comment and space (didn't think a space would cause an issue ... odd): <? session_start(); session_destroy(); header("location:Login.php"); ?> Thanks much, everyone, for the help! Link to comment https://forums.phpfreaks.com/topic/226194-how-do-i-do-a-log-off-link/#findComment-1167701 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.