blueman378 Posted May 21, 2008 Share Posted May 21, 2008 hi guys, well im trying to use this: part of index.php <?php if($_SESSION[loggedin] == 1) { $method = $_GET['method']; if($method == "catman") { include("categorymanager.php"); } elseif($method == "help") { include("help.php"); } elseif($method == "prodman") { include("productmanager.php"); } else { include("adminhome.php"); } } elseif($_POST[login] == 1) { $users->login($_POST[username], $_POST[password]); } else { echo "<form action=\"$_SERVER[php_SELF]\" method=\"post\"> <label for=\"username\">Username:</label> <input type=\"text\" name=\"username\"> <label for=\"password\">Password:</label> <input type=\"password\" name=\"password\"> <label for=\"remember\">Remember me?</label> <input type=\"checkbox\" name=\"remember\" value=\"1\"> <input type=\"hidden\" name=\"login\" value=\"1\"> <input type=\"submit\" value=\"Login\"> </form>"; } ?> the login class that it references <?php class users { function login($username, $password) //Check the users username and password combo { $username = trim(strtolower(preg_replace("/[^a-z \d]/i", "",$username))); $password = trim(preg_replace("/[^a-z \d]/i", "",$password)); $query = "Select * FROM users WHERE Username='$username' AND Password='$password'"; $result = mysql_query($query) or die(mysql_error()); $num_rows = mysql_num_rows($result); if($num_rows == 1) { while ($user = mysql_fetch_array($result)) { if($user[Active] == 1) { $_SESSION['username'] = "$user[username]"; $_SESSION['level'] = "$user[Level]"; $_SESSION['points'] = "$user[Points]"; $_SESSION['id'] = "$user[id]"; $_SESSION['email'] = "$user[Email]"; $_SESSION['loggedin'] = "1"; if($_POST[remember] || $_GET[remember]) { setcookie("id", "$user[id]", time()+31556926); } echo "username: $_SESSION[username] <br>"; echo "level: $_SESSION[level] <br>"; echo "points: $_SESSION[points] <br>"; echo "email: $_SESSION[email] <br>"; echo "loggedin: $_SESSION[loggedin] <br><hr>"; echo "username: $user[username] <br>"; echo "level: $user[Level] <br>"; echo "points: $user[Points] <br>"; echo "email: $user[Email] <br>"; } else{ echo "Your Account is either not activated to has been disabled by a administrator"; } } } else{ echo "Username/Password Combination do not match"; } } } ?> when i run it i get: username: admin level: 3 points: 0 email: webmaster@webspirited[killbot].com loggedin: 1 -------------------------------------------------------------------------------- username: admin level: 3 points: 0 email: webmaster@webspirited[killbot].com so both the sessions and the query are getting done correctly, however as soon as i try to go anywhere else it seems to kill the sessions or something, any ideas? Link to comment https://forums.phpfreaks.com/topic/106573-solved-login-not-working/ Share on other sites More sharing options...
blueman378 Posted May 21, 2008 Author Share Posted May 21, 2008 well i believe that the problem is a scope problem athough i was not aware that sessions had scope issues also? cheers Link to comment https://forums.phpfreaks.com/topic/106573-solved-login-not-working/#findComment-546298 Share on other sites More sharing options...
PFMaBiSmAd Posted May 21, 2008 Share Posted May 21, 2008 I don't see a session_start(); statement in the posted code. Ref: http://php.net/session_start Link to comment https://forums.phpfreaks.com/topic/106573-solved-login-not-working/#findComment-546422 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.