Jump to content

Logoff


akrytus

Recommended Posts

OK,  i have user login just fine and everything works great.  Now I am trying to create a logoff button to destroy the current session.  To do this I added:

[code]<a onMouseDown="<? session_destroy(); // Logoff Button ?>" href="http://www.nocrs.net"><img src="../Images/Blank%20Links/Submit_Blank.gif" alt="Logoff" width="33" height="20" border="0"></a>[/code]

This worked at first, then it started to destroy the session all on its own, with out having to click the button.  Is there a better way to do this or can you inform me what I have done wrong?
Link to comment
Share on other sites

[quote author=hitman6003 link=topic=103015.msg409738#msg409738 date=1154717535]
You can't execute php code from javascript, which is what you are trying to do. 
[code]onMouseDown="<? session_destroy(); // Logoff Button ?>" [/code]
As legohead said, you have to post to a page that destroys the session, then send them back to the page.
[/quote]

Ahh, but you can.  That is why my session keeps getting destroyed!  What I dont understand is why it worked for a while, but now does not.  I guess I will have to use a form. Thanks for the help!
Link to comment
Share on other sites

No need for a form.

make this [b]logout.php[/b]
[code]<?php
session_destroy();
header("Location: http://www.nocrs.net");
?>[/code]

Logout link:
[code]<a href="logout.php"><img src="../Images/Blank%20Links/Submit_Blank.gif" alt="Logoff" width="33" height="20" border="0"></a>[/code]
Link to comment
Share on other sites

When  you log out a user you must unset the session or the user will use the back button and be still  be logged in.

example below

log the user out with a get method link.
[code]
<a href="logout.php?logout=user">log out</a>
[/code]

[code]
<?php session_start();

if($_GET['logout']=="user"){

session_destroy();

unset($username);//session name.
unset($password);//session name.
unset($user_id);// session name.

// send user back to index page as properly logged out.
header("location: index.php");
}

?>
[/code]
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.