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
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?

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.