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

Link to comment
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.

 

Ok, but I'm following this tutorial and he has it.

 

http://www.youtube.com/embed/Z8nFtL6xC1A

 

How do you suggest I rewrite it?

Link to comment
Share on other sites

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  ;)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.