How To Make Login Form in PHP

PHP (PHP: Hypertext Processor) is a very widely-used scripting language, and the reasons why are obvious:   PHP integrates perfectly with plain HTML documents, is supported by the vast majority of Web hosting providers and has an easy-to-learn syntax, which you can also find in JavaScript, in some cases.

In this tutorial, we'll be experimenting with one of the much appreciated features of PHP: form processing.


We begin by creating a plain HTML document, for this tutorial, we'll be using HTML5.

<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Simple Login Form</title>
</head>
<body>
</body>
</html>
Once that is done, we'll want to add the actual form to the code. Inside the <body> </body> tags, place this:
<form action="#" method="post">
            <input type="text" name="u" />
            <input type="password" name="p" />
            <input type="submit" name="submit" value="Login" />
</form>
Now the fun begins, under the closing </html> tag, place this PHP script. Don't worry, we'll explain the code using comments.

<php
//This declares two variables, 'username' and 'password', the values of which you can change.
$username = "username";
$password = "password";
//Now, since the script will be running on the same document as the form, we want to make sure it doesn't process information that isn't there.
if (!$_POST["u"] or !$_POST["p"])
{
}
else
{
//If there is information provided, we'll make sure that it corresponds to the variables above, and then display the appropriate message.
if ($_POST["u"] == $username and $_POST["p"] == $password)
{
echo "You have been logged in!";
}
else
{
echo "The username or password was incorrect";
}
}
?>
That's it. Simple as that! You now know how to make an HTML for and process it's data using PHP.

1 comments:

Since fashion is renewing by the seasons, it involves a lot of replica watches online buying and auctions as well. Internet marketing has made its presence in the fashion industry. Fashion represents one's personal style and a taste of art. Every month, every one of hublot replica uk at least hundreds to thousands on what we are wearing. There are fake rolex sale and supplying sources to renew your closet every season. Now, it is no longer necessary to purchase directly from stores. E-buying is definitely the current trend. The replica watches are a favorite fashion choice with both men and women, every rolex replica likes to appear different from the others. At every day to day occasion, people want to sport a look which would ensure them maximum appreciation. In order to fulfill their desire, they take care to add something special to their style rolex replica sale which would make them stand apart from others. A watch is one such item which would help one buy respect and attention.

Reply

Post a Comment

Note: Only a member of this blog may post a comment.