Zoofu Posted July 30, 2009 Share Posted July 30, 2009 No errors, but it doesn't actually start the login session for some reason. <?php echo "<a href=\"./login.php\">Login</a> | <a href=\"./register.php\">Register</a>\n"; ?> <html> <head> <title>Zoofu.net | Login</title> <center> <img src="http://roquarters.usersboard.com/users/a4/41/84/33/album/zooful10.png" /> </center> </head> <body> <style type="text/css"> body { background-color:#EEE; color:#000; font-family:Tahoma; font-size:10pt; </style> </body> </html> <?php echo "<center><a href=\"./home.php\" >Home</a></center>" ?> <?php include "global.php"; if($_SESSION['uid']){ echo "<center>You are already logged in, <a href=\"./logout.php\">logout</a>?</center>\n"; }else { if(!$_POST['submit']){//1 echo "<center><table border=\"0\" cellspacing=\"3\" cellpadding=\"3\"></center>\n"; echo "<center><form method=\"post\" action=\"./login.php\"></center>\n"; echo "<center><tr><td>Username</td><td><input type=\"text\" name=\"username\"></td></tr></center>\n"; echo "<center><tr><td>Password</td><td><input type=\"password\" name=\"password\"></td></tr></center>\n"; echo "<center><tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"submit\"></td></tr></center>\n"; echo "<center></form></table></center>\n"; }else { $user = mss($_POST['username']); $pass = $_POST['password']; if($user && $pass){ $sql = "SELECT id FROM `users` WHERE `username`='".$user."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) > 0) { $sql2 = "SELECT id FROM `users` WHERE `username`='".$user."' AND `password` ='".md5($pass)."'"; $res2 = mysql_query($sql2) or die(mysql_error()); if(mysql_num_rows($res2) > 0){ $row = mysql_fetch_assoc($res2); $_SESSION['uid'] = $row['id']; echo "<center>You have logged in successfully! <a href=\"./home.php\">Return To Home</a></center>\n"; }else { echo "<center>Username or password are incorrect! <a href=\"./login.php\">Retry?</a></center>\n"; } }else { echo "<center>The Username you supplied does not exist! <a href=\"./login.php\">Retry?</a></center>\n"; } }else { echo "<center>You must fill in all fields! <a href=\"./login.php\">Retry?</a></center>"; } } }//1 ?> Quote Link to comment https://forums.phpfreaks.com/topic/168216-login-failure/ Share on other sites More sharing options...
lonewolf217 Posted July 30, 2009 Share Posted July 30, 2009 you need session_start(); at the beginning of the page Quote Link to comment https://forums.phpfreaks.com/topic/168216-login-failure/#findComment-887265 Share on other sites More sharing options...
Zoofu Posted July 30, 2009 Author Share Posted July 30, 2009 Why? I need it to start when you click Login. Quote Link to comment https://forums.phpfreaks.com/topic/168216-login-failure/#findComment-887266 Share on other sites More sharing options...
lore_lanu Posted July 31, 2009 Share Posted July 31, 2009 To use sessions, you must have session_start; at the top of your page. Regardless of whether you are echoing or setting them. Quote Link to comment https://forums.phpfreaks.com/topic/168216-login-failure/#findComment-887280 Share on other sites More sharing options...
Philip Posted July 31, 2009 Share Posted July 31, 2009 No errors, but it doesn't actually start the login session for some reason.Wouldn't it make sense to have PHP start the sessions then? You call a session var, but sessions aren't started in the script thus it won't work. $_SESSION['uid'] = $row['id']; Quote Link to comment https://forums.phpfreaks.com/topic/168216-login-failure/#findComment-887282 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.