PHP : Login Form Without Database , session and cookies
|
PHP : Login Form Without Database , session and cookies
Today's topic you will learn how to create a simple login form using PHP and HTML commands without using a database , session and cookies. First methodStep No : 1 Create a page called login.html.Step No : 2 Now copy and paste this code into login.html. Step No : 3 Then save. Code :
<html> <head> </head> <body> <div> <h2>LOGIN</h2> </div> <form action="login.php" method="post" > <div> <label>User Name</label> <input type="text" name="user" /> </div> <div> <label>Password</label> <input type="password" name="password" /> </div> <div> <input type='submit' name="Login" /> </div> </form> </body> </html> Step No : 4 Create a page called login.php. Step No : 5 Now copy and paste this code into login.php. Step No : 6 Then save.
<?php $user = $_POST["user"]; $password = $_POST["password"]; if ( $user == "admin" and $password == "password" ) { echo "Login successful"; }else{ echo "The username and password entered do not match. please try again"; } ?> The login page has been created. Second methodThis way we will create a login form on the same page and check if the user and password are correct.But to create such a page you need to add more code. These codes will also be explained here. Step No : 1 Create a page called login.php. Step No : 2 Now copy and paste this code into login.php. Step No : 3 Then save.
<?php if ( !empty ( $_POST["login"] ) ) { $user = $_POST["user"]; $password = $_POST["password"]; if ( $user == "admin" and $password == "password" ) { echo "Login successful"; }else{ echo "The username and password entered do not match. please try again"; } }else{ ?> <html> <head> </head> <body> <div> <h2>LOGIN</h2> </div> <form action="login.php" method="post" > <div> <label>User Name</label> <input type="text" name="user" /> </div> <div> <label>Password</label> <input type="password" name="password" /> </div> <div> <input type='submit' name="login" /> </div> </form> </body> </html> <?php } ?> |
Share This:
|
Subscribe to:
Posts (Atom)
No comments:
Post a Comment