Jump to content

My login form is not being displayed


KDM

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/233335-my-login-form-is-not-being-displayed/
Share on other sites

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.

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?

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.

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 .= ' 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.