coldkill Posted October 12, 2006 Share Posted October 12, 2006 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,ColdThe 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 More sharing options...
tleisher Posted October 12, 2006 Share Posted October 12, 2006 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 https://forums.phpfreaks.com/topic/23807-sessiondb-error-solved/#findComment-108139 Share on other sites More sharing options...
coldkill Posted October 13, 2006 Author Share Posted October 13, 2006 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 https://forums.phpfreaks.com/topic/23807-sessiondb-error-solved/#findComment-108260 Share on other sites More sharing options...
coldkill Posted October 13, 2006 Author Share Posted October 13, 2006 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 https://forums.phpfreaks.com/topic/23807-sessiondb-error-solved/#findComment-108420 Share on other sites More sharing options...
coldkill Posted October 14, 2006 Author Share Posted October 14, 2006 Still need help with this please. The sql query does return a handler so it does query the database and find data. Cold Link to comment https://forums.phpfreaks.com/topic/23807-sessiondb-error-solved/#findComment-108788 Share on other sites More sharing options...
coldkill Posted October 14, 2006 Author Share Posted October 14, 2006 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 Link to comment https://forums.phpfreaks.com/topic/23807-sessiondb-error-solved/#findComment-108803 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.