akrytus Posted August 4, 2006 Share Posted August 4, 2006 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 https://forums.phpfreaks.com/topic/16578-logoff/ Share on other sites More sharing options...
legohead6 Posted August 4, 2006 Share Posted August 4, 2006 just make a form have only the submit button in it that makes them logoff then use this code[code]if(isset($_POST['logout'])){$_SESSION = array();SESSION_DESTROY();header ("location: Location after logout");}[/code] Link to comment https://forums.phpfreaks.com/topic/16578-logoff/#findComment-69367 Share on other sites More sharing options...
hitman6003 Posted August 4, 2006 Share Posted August 4, 2006 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. Link to comment https://forums.phpfreaks.com/topic/16578-logoff/#findComment-69369 Share on other sites More sharing options...
akrytus Posted August 4, 2006 Author Share Posted August 4, 2006 [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 https://forums.phpfreaks.com/topic/16578-logoff/#findComment-69377 Share on other sites More sharing options...
hitman6003 Posted August 4, 2006 Share Posted August 4, 2006 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. Link to comment https://forums.phpfreaks.com/topic/16578-logoff/#findComment-69379 Share on other sites More sharing options...
Prismatic Posted August 5, 2006 Share Posted August 5, 2006 No need for a form.make this [b]logout.php[/b][code]<?phpsession_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 https://forums.phpfreaks.com/topic/16578-logoff/#findComment-69540 Share on other sites More sharing options...
redarrow Posted August 5, 2006 Share Posted August 5, 2006 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 belowlog 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 https://forums.phpfreaks.com/topic/16578-logoff/#findComment-69589 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.