AStrangerWCandy Posted August 31, 2009 Share Posted August 31, 2009 Is $_POST required prior to using $_GET? I have a hyperlink which is index.php?action=logout When that link is clicked Im trying to get it to unset the logged in session variable. I have this code: if ($_GET['action'] = logout) which unsets the variable if its true, however $_GET['action'] does not ever seen to equal anything. I've been trying to print it to see what the problem is as no error is generated and I get nothing. Am I going about this the wrong way? Quote Link to comment https://forums.phpfreaks.com/topic/172618-_get-not-working/ Share on other sites More sharing options...
mikesta707 Posted August 31, 2009 Share Posted August 31, 2009 you have to surround strings with quotation marks. that will try to find a constant logout and since there is none, that will always run false if ($_GET['action'] = "logout") Quote Link to comment https://forums.phpfreaks.com/topic/172618-_get-not-working/#findComment-909901 Share on other sites More sharing options...
MartinGr Posted August 31, 2009 Share Posted August 31, 2009 What you are currently doing is assigning value 'logout' to $_GET['action']. Actually the solution is really easy if ($_GET['action'] == "logout") Quote Link to comment https://forums.phpfreaks.com/topic/172618-_get-not-working/#findComment-909905 Share on other sites More sharing options...
AStrangerWCandy Posted August 31, 2009 Author Share Posted August 31, 2009 Indeed you guys are awesome I'm still a beginner. Finally made a system of logging in that works great, validates and crypts but some simple stuff like this still trips me up. I am now returning the proper value however I have a feeling im using unset improperly. the rest of the code is as follows: if ($_GET['action'] == "logout") { unset ($_SESSION['loggedin']); It dosnt seem to actually unset that variable when the link is clicked or page refreshed. Quote Link to comment https://forums.phpfreaks.com/topic/172618-_get-not-working/#findComment-909906 Share on other sites More sharing options...
mikesta707 Posted August 31, 2009 Share Posted August 31, 2009 unset pretty much just creates a whole in your session array. It will take out the value of the array at that key, but the key is still preserved. You also want to do session_destroy() to completely destroy the session Quote Link to comment https://forums.phpfreaks.com/topic/172618-_get-not-working/#findComment-909907 Share on other sites More sharing options...
AStrangerWCandy Posted August 31, 2009 Author Share Posted August 31, 2009 Hrm I switched it to session_destoy() and had both the unset and session destroy and neither one logged the person out. It removed the variables indicating username and whatnot but the logged in session variable remains. I even had it print the session variable right after session_destroy and that variable remains Quote Link to comment https://forums.phpfreaks.com/topic/172618-_get-not-working/#findComment-909909 Share on other sites More sharing options...
AStrangerWCandy Posted August 31, 2009 Author Share Posted August 31, 2009 Might be better if I post the whole code of what I'm trying to do: <?php require("header.php"); // The banner logo and ad app. Also begins the overall page table. if ($_GET['action'] == "logout") { unset ($_SESSION['loggedin']; session_destroy(); require("sidebar.php"); // The app that determines if you're logged in, if logged in displays sidebar menu, if not offers login/signup require("announcements.php"); // Gives main page with announcements require("footer.php"); // Copyright info and ties up the overall page table. } else { require("sidebar.php"); // The app that determines if you're logged in, if logged in displays sidebar menu, if not offers login/signup require("announcements.php"); // Gives main page with announcements require("footer.php"); // Copyright info and ties up the overall page table. } sidebar.php is where the login box is and it starts off with: if ($_SESSION[loggedin] = yes) { and on from there Quote Link to comment https://forums.phpfreaks.com/topic/172618-_get-not-working/#findComment-909916 Share on other sites More sharing options...
MartinGr Posted August 31, 2009 Share Posted August 31, 2009 Hrm I switched it to session_destoy() and had both the unset and session destroy and neither one logged the person out. It removed the variables indicating username and whatnot but the logged in session variable remains. I even had it print the session variable right after session_destroy and that variable remains Do you have session_start() at the beginning of the file you are using this code at? Edited: Apparently not. Add it and both, unset and session_destroy() should work. Quote Link to comment https://forums.phpfreaks.com/topic/172618-_get-not-working/#findComment-909920 Share on other sites More sharing options...
AStrangerWCandy Posted August 31, 2009 Author Share Posted August 31, 2009 of index.php? no I dont session_start() is the first line of the header.php that I require on all pages Quote Link to comment https://forums.phpfreaks.com/topic/172618-_get-not-working/#findComment-909924 Share on other sites More sharing options...
MartinGr Posted August 31, 2009 Share Posted August 31, 2009 Try using session_unset() before session_destroy() Quote Link to comment https://forums.phpfreaks.com/topic/172618-_get-not-working/#findComment-909928 Share on other sites More sharing options...
AStrangerWCandy Posted August 31, 2009 Author Share Posted August 31, 2009 Added that in and the variable is still not going away Quote Link to comment https://forums.phpfreaks.com/topic/172618-_get-not-working/#findComment-909929 Share on other sites More sharing options...
AStrangerWCandy Posted August 31, 2009 Author Share Posted August 31, 2009 I also should probably add the loggedin session variable is being set within a function Quote Link to comment https://forums.phpfreaks.com/topic/172618-_get-not-working/#findComment-909948 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.