Jump to content

Recommended Posts

This is the most strange problem i have come accross, i cant see any problems with my code and i have tried everything i can think of to try and fix it but yet the problem still persists

 

here is my sentry.php file

<?php
class Sentry
{
	var $loggedin = false;
	var $userdata;

	function sentry()
	{
		session_start();
		header("Cache-control: private"); 
	}

	function logout()
	{
		unset($this->userdata);
		session_destroy();
		return true;
	}

	function checkLogin($user = '',$pass = '',$group = 10,$goodRedirect = '',$badRedirect = '')
	{
		require_once('DBConnector.php');
		require_once('Validator.php');
		$validate = new Validator();
		$connector = new DBConnector();

		if($_SESSION['user'] && $_SESSION['pass'])
		{
			if(!$validate->validateTextOnly($_SESSION['user']))
			{
				return false;
			}
			if(!$validate->validateTextOnly($_SESSION['pass']))
			{
				return false;
			}

			$getUser = $connector->Query("SELECT * FROM members WHERE Username='" . $_SESSION['user'] . "' AND Password='" . $_SESSION['pass'] . "' AND Group<='" . $group . "' AND Status=1");

			if($connector->GetNumRows($getUser) > 0)
			{
				if($goodRedirect != '')
				{
					header("Location: ".$goodRedirect."?".strip_tags(session_id())) ;
				}
				return true;
			}else{
				$this->logout();
				return false;
			}
		}else{
			if(!$validate->validateTextOnly($user))
			{
				return false;
			}
			if(!$validate->validateTextOnly($pass))
			{
				return false;
			}

			$getUser = $connector->Query('SELECT * FROM members WHERE Username="$user" AND Password=MD5("$pass") AND Group<="$group" AND Status="1"');
			$this->userdata = $connector->GetArray($getUser);

			if($connector->GetNumRows($getUser) > 0)
			{
				$_SESSION["user"] = $user;
				$_SESSION["pass"] = $this->userdata['Password'];
				$_SESSION["group"] = $this->userdata['Group'];

				if ($goodRedirect)
				{
					header("Location: ".$goodRedirect."?".strip_tags(session_id()));
				}
				return true;
			}else{
				unset($this->userdata);
				if ($badRedirect)
				{
					header("Location: ".$badRedirect);
				}
				return false;
			}
		}
	}
}
?>

 

 

the problem is with the query line that is supposed to return the resource id

$getUser = $connector->Query('SELECT * FROM members WHERE Username="$user" AND Password=MD5("$pass") AND Group<="$group" AND Status="1"');

 

it doesnt store or return any value, e.g. if i echo it normally it would say something like Resource #id3, but nothing if i echo it it returns nothing at all, my query is correct i am sure as i have tested it in phpmyadmin by means of sql querying and it returs values then.

 

here are some additional errors that dont make sense other than the fact it is because the query returns nothing that are displayed at the top of the login.php page when you try to login

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in H:\xampp\htdocs\phpcms\includes\DBConnector.php on line 41

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in H:\xampp\htdocs\phpcms\includes\DBConnector.php on line 36

Warning: Cannot modify header information - headers already sent by (output started at H:\xampp\htdocs\phpcms\includes\DBConnector.php:41) in H:\xampp\htdocs\phpcms\includes\Sentry.php on line 79

 

hope someone can spot anything i have missed coz im stumped on this one

 

p.s. just as a side note if i remove the part that checks the group of the user then the query does return the resource id as it should do which is Resource id #8, but the query returns no results when i know it should do

 

p.s.s. im am wondering if there is a limit or something to the ammount of queries that i can submit to my db swell as the length of them, if there is a memory setting for this in the php.ini file or something then please let me know, i have full controll over my site and all of the settings so im pretty sure i would be able to change things if you explained how i would do them

 

cheers

 

Craig

Your problem is here.

 

$getUser = $connector->Query('SELECT * FROM members WHERE Username="$user" AND Password=MD5("$pass") AND Group<="$group" AND Status="1"');

 

You should put the string in double quotes "", because only then variables inside will be evaluated.

fekin HI 5 man thanks a lot for that one, i dont use too many of the mysql commands as i dont need them, i just changed it to UGroup in my db and on the query and it now all works perfectly

 

respect to you and thanks muchly

 

cheers

 

Craig

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.