I just started getting into php recently and I wanted to create a simple login with(out any SQL (haven't learned it yet :$). So Here is my code for login page:

<form action="index.php" method="post">
			Username<input type="text" name="user" /> <br />
			Password<input type="password" name="pass" /> <br />
			<input type="submit" />
		</form>

	<?php
		$username = username;
		$password = password;
		
		$iusername = $_POST["user"];
		$ipassword = $_POST["pass"];
		
		if ($username==$iusername && $password==$ipassword) {
			include('../0340791aacd04a07560cd7dc983ed98e.php');
		}else{
			echo 'Incorrect pass';
		}
	?>

Now the problem is,

Recommended Answers

All 3 Replies

hmm

<form action="index.php" method="post">
    Username <input type="text" name="username" /> <br />
    Password<input type="password" name="password" /> <br />
    <input type="submit" />
</form>
     
<?php
$iusername = 'user';
$ipassword = 'pass';

$username = $_POST["username"];
$password = $_POST["password"];

if(!$username && !$password)
{
	echo 'No sign in name entered or password';
}
else if($username == $iusername && $password == $ipassword)
{
	include('./0340791aacd04a07560cd7dc983ed98e.php');
	echo '=)';
}
else
{
	echo 'Incorrect pass';
}
?>

Oops! Forgot to finish the thread. The problem is, It says "Incorrect password" even on the first load (when someone goes to the page, and doesnt even type a username/pass). I get why this is happening. How can I make it so it only says "incorrect pass" after 1 attempt? Not just when there is no information sent through $_POST?

<?php

$form = <<<EOT
<form action={$_SERVER["PHP_SELF"]} method="post" enctype="multipart/form-data">
    <label for="username">Username:</label>
    <input type="text" name="username" />
    <br /><br />
    <label for="password">Password:</label>
    <input type="password" name="password" />
    <br />
    <input type="submit" name="submit" value="Submit" />
</form>

EOT;

if(isset($_POST['submit'])){
//do stuffs
print_r($_POST);

}else{
 echo $form;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.