PHP Simple login Form - Part 1

In this blog we will learn to create a simple login form without using the database. We will be using harcoded username and password in authenticating file itself.

We will be creating two PHP file:
1. login.php
2. login_process.php


login.php

<html>

  <head>

    <title>Login Form</title>

  </head>



<body>

<form name="login" method="post" action="login_process.php">

    Username: <input type="text" name="username"/>

    Password: <input type="password" name="password"/>

    <input name="submit" type="submit" />

</form>

</body>

</html>



 login_process.php

<?php



// Following are the hardcoded username and   password for the login form. If user types anything else than below   value user wont be able to login.


$username = "myusername";

$password = "mypassword;




//Check if the input from the login.php are equal to our hardcoded variable


if($username == $_GET['username'] && $password =='$_GET['password']')

{

echo "Login success!";


} else {

echo "Login Failed!";


}





?>


Now browse the login.php in your broswer. Enter "myusername" as username and "mypassword" as password. Click on submit button will result with message "Login Success".

Else anything will display message "Login failed".


Thank you!

Share this

0 Comment to " PHP Simple login Form - Part 1 "

Post a Comment