Jump to content

Session/db error ::SOLVED::


coldkill

Recommended Posts

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:
[code]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" );
}[/code]
Link to comment
https://forums.phpfreaks.com/topic/23807-sessiondb-error-solved/
Share on other sites

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.
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
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.