Login Check Module using PHP and HTML
Implementing Login Check using PHP and HTML
In this article we are going to learn how to create a simple Login form using HTML and How to check Login is successful or invalid using PHP Coding. So create a file called login.php and copy and paste the below code and save it on the server, in some folder. In this file you will see 2 parts. One is the login form code and above the PHP code.
Login form having form tag with name, action, method attributes. Next 2 input tags, one is username - text box- called 'username' and another input tag type password and its name is 'password'. Another input tag is Submit button.
When the User submits
the form, then the data the user submitted (username, password) will be
transmitted to the server in the form of the post method. PHP checks whether the Submit button is clicked or not, then reads
those
posted values using name attributes and stores them in PHP variables. Next, It compares them with some constant values and returns success if user values matches with constant values. If not, then it displays an invalid message.
login.php
<html lang="en"> <head> <title>e-trainings Demo - creating Login form with HTML and PHP</title> <meta charset="utf-8"></meta> </head> <body> <?php if(isset($_POST['submit'])) { $username = $_POST['username']; $password = $_POST['password']; if($username == "admin" and $password == "admin123"){ print "Login Success!!"; } else { print "Login Failed"; } } ?> <form name="loginform" action="#" method="post" > <center>
<h2>Login Details</h2>
</center> Username <input type="text" name="username"><br /> Password <input type="password" name="password"><br /><br /> <input name="submit" type="submit" value="Login" /> New User? <a href="Signup.php">Signup Here</a> </form> </body> </html>
Result:
Next Build SignupForm in PHP
Comments
Post a Comment