Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/64852-invalid-session-being-displayed/
Share on other sites

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

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.