Jump to content

Simple Login Form


phpMyTony

Recommended Posts

Hi Tony,

 

You could post your code and allow us to pick at it, giving you pointers here and there?

 

First thing I noticed is that you're giving me an access denied message before I even attempt to enter my password? That shouldn't really be the case. How about only showing that message if they have an incorrect login?

Link to comment
https://forums.phpfreaks.com/topic/150579-simple-login-form/#findComment-791598
Share on other sites

That is what I need to sort out. I am not sure how to do it, as I am very new to SMF.

 

Here's the code:

 

<html>
<head />
<body>

<form action="index.php" method=POST>
Full Name: <input type=text name=name><br />
Age: <input type=text name=age><br />
Password: <input type=password name=pass><br />
<input type=submit value="Authenticate!"><p>
</form>

<?php

$name=$_POST['name'];
$age=$_POST['age'];
$pass=$_POST['pass'];

if (($name=="Tony Perez") && ($age=="13") && ($pass=="999")) echo "Correct. Redirecting...";
else echo "Incorrect. Please check spelling.";

?>

</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/150579-simple-login-form/#findComment-791830
Share on other sites

I made some comments.

 

<?php

//assume that the login is not correct
$login_correct = false;

//lets check to see if the form was actually submitted or not
if(isset($_POST['name'])){ //if post variable 'name' is set, form has been submitted

$name = $_POST['name'];
$age = $_POST['age'];
$pass = $_POST['pass'];

//check details to see if they match
if (($name=="Tony Perez") && ($age=="13") && ($pass=="999")){
	$login_correct = true; //set $login_correct to true if details match
}
}

?>

<html>
<head>
<title>Login page</title>
</head>
<body>

<?php
//if $login_correct = true, login went well
if($login_correct){
echo '<strong>Login correct</strong><br />';
}
//else if $login_correct = false AND the form is known to have been submitted, login failed
else if(!$login_correct && isset($_POST['name'])){
echo '<strong>Login incorrect</strong><br />';
}

?>
<form action="index.php" method=POST>
Full Name: <input type=text name=name><br />
Age: <input type=text name=age><br />
Password: <input type=password name=pass><br />
<input type=submit value="Authenticate!"><p>
</form>


</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/150579-simple-login-form/#findComment-791856
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.