Jump to content

How do I do a "Log Off" link ??


spacepoet

Recommended Posts

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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.