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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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