Jump to content


Photo

Logoff


  • Please log in to reply
6 replies to this topic

#1 akrytus

akrytus
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts

Posted 04 August 2006 - 06:48 PM

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:

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

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?

#2 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 04 August 2006 - 06:49 PM

just make a form have only the submit button in it that makes them logoff then use this code

if(isset($_POST['logout'])){
$_SESSION = array();
SESSION_DESTROY();
header ("location: Location after logout");
}

"Syntax error" .. WHERE THE **** IS IT?!

#3 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 04 August 2006 - 06:52 PM

You can't execute php code from javascript, which is what you are trying to do. 
onMouseDown="<? session_destroy(); // Logoff Button ?>"
As legohead said, you have to post to a page that destroys the session, then send them back to the page.

#4 akrytus

akrytus
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts

Posted 04 August 2006 - 07:07 PM

You can't execute php code from javascript, which is what you are trying to do. 

onMouseDown="<? session_destroy(); // Logoff Button ?>"
As legohead said, you have to post to a page that destroys the session, then send them back to the page.


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!

#5 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 04 August 2006 - 07:11 PM

It's not executing when the user presses the link in the page.  the session_destroy is executed when the page loads, regardless of wether the user clicks the link.

#6 Prismatic

Prismatic
  • Members
  • PipPipPip
  • Advanced Member
  • 503 posts
  • LocationSan Diego

Posted 05 August 2006 - 12:15 AM

No need for a form.

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

Logout link:
<a href="logout.php"><img src="../Images/Blank%20Links/Submit_Blank.gif" alt="Logoff" width="33" height="20" border="0"></a>


#7 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 05 August 2006 - 02:45 AM

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.
<a href="logout.php?logout=user">log out</a>

<?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");
}

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users