KDM Posted April 11, 2011 Share Posted April 11, 2011 when I test this script on browser. This is all that I see. invalid username or password <?php //start session session_start(); include 'functions.php'; if (loggedin()) { header("Location: userarea.php"); exit(); } if ($_POST['login']) { //get data $username = $_POST['username']; $password = $_POST['password']; $rememberme = $_POST['rememberme']; } if (username&&$password) { $login = mysql_query("SELECT * FROM users WHERE username='$username'"); while ($row = mysql_fetch_assoc($login)) { $db_password = $row['password']; if (md5($password)==$db_password) $loginok =TRUE; else $loginok = FALSE; if ($loginok ==TRUE); { if($rememberme=="on") setcookie("username",$username, time()+7200); else if ($rememberme=="") $_SESSION['username']=$username; header("Location: userarea.php"); exit(); } } } else { die("invalid username or password"); } ?> <form action="login.php" method="POST"> username:<br /> <input type="text" name="username" /><br /> password:<br /> <input type="password" name="password" /><br /> <input type="checkbox" name="rememberme">remember me<br /> <input type="submit" name="login" value="Log in" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/233335-my-login-form-is-not-being-displayed/ Share on other sites More sharing options...
Pikachu2000 Posted April 11, 2011 Share Posted April 11, 2011 The problem is that die() kills the script dead in its tracks, additionally the logic shouldn't let the die() even be reached if the form hasn't been submitted. Even at that, die() is probably the worst way to handle form errors. Quote Link to comment https://forums.phpfreaks.com/topic/233335-my-login-form-is-not-being-displayed/#findComment-1199924 Share on other sites More sharing options...
KDM Posted April 11, 2011 Author Share Posted April 11, 2011 The problem is that die() kills the script dead in its tracks, additionally the logic shouldn't let the die() even be reached if the form hasn't been submitted. Even at that, die() is probably the worst way to handle form errors. Ok, but I'm following this tutorial and he has it. http://www.youtube.com/embed/Z8nFtL6xC1A How do you suggest I rewrite it? Quote Link to comment https://forums.phpfreaks.com/topic/233335-my-login-form-is-not-being-displayed/#findComment-1199926 Share on other sites More sharing options...
Vel Posted April 11, 2011 Share Posted April 11, 2011 I highly recommend you take a look at this tutorial: http://www.phpeasystep.com/phptu/6.html I found it very easy to follow and most useful. Quote Link to comment https://forums.phpfreaks.com/topic/233335-my-login-form-is-not-being-displayed/#findComment-1199974 Share on other sites More sharing options...
mikhl Posted April 11, 2011 Share Posted April 11, 2011 I think that where you have stated if(username&&$password) You were mention to say if($username&&$password) - declaring the username variable. Don't think that this is the reason that you are having this problem though Quote Link to comment https://forums.phpfreaks.com/topic/233335-my-login-form-is-not-being-displayed/#findComment-1199977 Share on other sites More sharing options...
Pikachu2000 Posted April 11, 2011 Share Posted April 11, 2011 I highly recommend you take a look at this tutorial: http://www.phpeasystep.com/phptu/6.html I found it very easy to follow and most useful. The tutorials on that site are mostly obsolete, and shouldn't be used. Quote Link to comment https://forums.phpfreaks.com/topic/233335-my-login-form-is-not-being-displayed/#findComment-1200066 Share on other sites More sharing options...
KDM Posted April 11, 2011 Author Share Posted April 11, 2011 Ok I've learned something after I found another login script with the remember feature, but I need help implementing the script into my site. This code displays the old form perfectly $head .= ' <form method="post" method="index2.php"> <div style="margin-bottom:10px; margin-top:20px; color:#FFFFFF">login <br /> <input class="inputfields" type="text" name="username" /> </div> <div style="margin-bottom:10px; color:#FFFFFF"> password <input class="inputfields" type="password" name="pwd" /> </div> <div><input type="submit" name="login" value="Login" /></div> </form>'; But when I replace the above code with the following code, my new form is not being displayed. Instead of the new form showing up, it just shows the actual code where the form should be displayed $head .= ' include("login.php"); displayLogin();'; What is this saying anyway? $head .= ' Quote Link to comment https://forums.phpfreaks.com/topic/233335-my-login-form-is-not-being-displayed/#findComment-1200230 Share on other sites More sharing options...
sadavied Posted April 11, 2011 Share Posted April 11, 2011 That is saying "append everything between ' and ' to the variable named head". Somewhere in the page that 'head' variable is probably echo'd (in the <body> tag, most likely). Quote Link to comment https://forums.phpfreaks.com/topic/233335-my-login-form-is-not-being-displayed/#findComment-1200294 Share on other sites More sharing options...
Pikachu2000 Posted April 11, 2011 Share Posted April 11, 2011 The .= is a concatenating assignment operator. Quote Link to comment https://forums.phpfreaks.com/topic/233335-my-login-form-is-not-being-displayed/#findComment-1200298 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.