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
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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.