Perad Posted August 14, 2007 Share Posted August 14, 2007 I want this code to check if the session "user" is up and running. if so set a variable to true, otherwise set it to guest... however it seems to be setting the variable to guest no matter what the session is set to. I'm staring at this bit of code and just cannot see what is wrong. Can anyone help me out? public function loginCheck() { if (isset($_SESSION['user'])) { $this->loggedin = TRUE; } else { $_SESSION['id'] = "0"; $_SESSION['user'] = "Guest"; } } Quote Link to comment https://forums.phpfreaks.com/topic/64852-invalid-session-being-displayed/ Share on other sites More sharing options...
akitchin Posted August 14, 2007 Share Posted August 14, 2007 how/when are you assigning $_SESSION['user'] to anything other than 'Guest'? Quote Link to comment https://forums.phpfreaks.com/topic/64852-invalid-session-being-displayed/#findComment-323629 Share on other sites More sharing options...
NArc0t1c Posted August 14, 2007 Share Posted August 14, 2007 Also, destroy unneeded sessions. unset($_SESSION['id']); Quote Link to comment https://forums.phpfreaks.com/topic/64852-invalid-session-being-displayed/#findComment-323636 Share on other sites More sharing options...
Perad Posted August 14, 2007 Author Share Posted August 14, 2007 0 is the id of a guest, perhaps I better change that to -1. I am only changing it when the user log's in. My class so far. class Login { public $message; public $error; public $loggedin; private function cleanString($string) { $string = trim($string); $string = stripslashes($string); $string = strip_tags($string); return $string; } public function loginCheck() { if (isset($_SESSION['user'])) { $this->loggedin = TRUE; } else { $_SESSION['id'] = "0"; $_SESSION['user'] = "Guest"; } } public function parseLogin($user, $pass) { $clean_user = $this->cleanString($user); $clean_pass = md5($this->cleanString($pass)); $sql = "SELECT username FROM member WHERE password='$clean_pass'"; $result = mysql_query($sql); if (mysql_num_rows($result)) { $sql = "SELECT id FROM member WHERE username='$clean_user'"; $result = mysql_query ($sql); $row = (mysql_fetch_assoc($result)); unset($_SESSION['id']); unset($_SESSION['user']); $_SESSION['id'] = $row['id']; $_SESSION['user'] = $clean_user; } } } Quote Link to comment https://forums.phpfreaks.com/topic/64852-invalid-session-being-displayed/#findComment-323641 Share on other sites More sharing options...
akitchin Posted August 14, 2007 Share Posted August 14, 2007 then the $_SESSION['user'] will always be 'Guest' unless the user logs in, successfully. otherwise, the id and user will always be the defaults. Quote Link to comment https://forums.phpfreaks.com/topic/64852-invalid-session-being-displayed/#findComment-323645 Share on other sites More sharing options...
NArc0t1c Posted August 14, 2007 Share Posted August 14, 2007 If you want to keep the value, use Cookies. Reason: Sessions gets destroyed when the user will logout or close browser, Cookies don't. Quote Link to comment https://forums.phpfreaks.com/topic/64852-invalid-session-being-displayed/#findComment-323649 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.