Jump to content


Photo

Session/db error ::SOLVED::


  • Please log in to reply
5 replies to this topic

#1 coldkill

coldkill
  • Members
  • PipPipPip
  • Advanced Member
  • 159 posts
  • LocationUnited Kingdom

Posted 12 October 2006 - 11:21 PM

Hey folks got a little problem with a login script. When the user logs in they login fine their username and password are found in the database and everything but when they go onto the next page the 2 sessions which come out the database have no value although they are set and you can access them. I'm not sure what the problem is since I tried displaying the values out of the DB and they didn't work but the DB script has to work otherwise the entire site wouldn't. So I'm really stumped on this one :S.

This function is part of a class all the key things like session start the db connection etc are done on other pages. But I'm certain this is where the problem emenates from.

Thanks in advance,
Cold

The script:
function execute()
	{
		/*
		*	Make those strings safe!
		*/
		$username = $this->DB->add_slashes( $_POST['username'] );
		
		/*
		*	Encrypt the password
		*/
		$password = md5( $_POST['password'] );
		
		/*
		*	Did they enter the correct info?
		*/
		$sql = $this->DB->query( "SELECT * FROM members WHERE username='".$username."' AND password='".$password."' LIMIT 1" );
		
		if( empty( $sql ) )
		{
			/*
			*	Incorrect something or other
			*/
			$this->STYLE->bump( "index.php?module=login&err=inc" );
		}
		
		/*
		*	Still going? It's all good!
		*
		*	Fetch The data
		*/
		$row = $this->DB->fetch_row( $sql );
		
		$id = $row["id"];
		$level = $row["user_level"];
		
		
		/*
		*	Set the sessions
		*/
		$_SESSION["username"] = $username;
		$_SESSION["user_level"] = $level;
		$_SESSION["id"] = $id;
		
		echo $level;
		echo $id;
		echo $username;
		
		
		/*
		*	Auto login?
		*/
		if( ! empty( $_POST['auto_login'] ) )
		{
			/*
			*	Set the cookies
			*/
			setcookie( "aaluname", $username, time()+60*60*24*180 );
			setcookie( "aalpword", $password, time()+60*60*24*180 );
		}
		
		//$this->STYLE->bump( DOMAIN."index.php?display=logged_in" );
	}



You can learn alot from reading the manual

#2 tleisher

tleisher
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts

Posted 12 October 2006 - 11:47 PM

session_start();

Is that at the top of your file? Also, have you tried echoing the $_SESSION variables?

One thing you may want to try is renaming the session info, I think its php 4 that allows session names to be used in the same way as normal variables, so $username and $_SESSION["username"] are the same thing, which is a bad way of programming and stumped me for a while as well.

#3 coldkill

coldkill
  • Members
  • PipPipPip
  • Advanced Member
  • 159 posts
  • LocationUnited Kingdom

Posted 13 October 2006 - 11:20 AM

Yeah session_start is at the top (or before any header output). I didn't know that they would count as the same thing though so I'll try renamming them.

I did try echoing the session vars I also used the functions isset and empty to check if they were actually set or just empty.

Cold


You can learn alot from reading the manual

#4 coldkill

coldkill
  • Members
  • PipPipPip
  • Advanced Member
  • 159 posts
  • LocationUnited Kingdom

Posted 13 October 2006 - 04:20 PM

Didn't work...

It may be the database function but I tried using mysql_fetch_array instead of one loaded from my class and it came up with the same result.

Even though nothing is returned from the function there is no error being output by the database so this just has me completely stumped.

Thanks for the help,
Cold


You can learn alot from reading the manual

#5 coldkill

coldkill
  • Members
  • PipPipPip
  • Advanced Member
  • 159 posts
  • LocationUnited Kingdom

Posted 14 October 2006 - 02:15 PM

Still need help with this please.

The sql query does return a handler so it does query the database and find data.

Cold


You can learn alot from reading the manual

#6 coldkill

coldkill
  • Members
  • PipPipPip
  • Advanced Member
  • 159 posts
  • LocationUnited Kingdom

Posted 14 October 2006 - 03:11 PM

OK I think I've isolated the problem.

The query returns a handler. The fetch_array function doesn't return anything although it is defined it is empty. Any ideas why this might happen?

Thanks,
Cold


You can learn alot from reading the manual




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users