How to Make Login Form in PHP

How to make login form in php - Login is one useful feature to ensure that a system can only be used by users who are eligible to use the app. To better understand what kind of login form, here is an example of the login form program in php.
Program 1
File Name: input05.php
Description: The program displays the login form (input text and password).
Open notepad, then type the following html code.
<html>
<head><title>Login Here</title></head>
<body>
  <FORM ACTION="proses05.php" METHOD="POST" NAME="input">
<h2>Login Here...</h2>
   Username : <input type="text" name="username"><br>
   Password : <input type="password" name="password"><br>
   <input type="submit" name="Login" value="Login">
   <input type="reset" name="reset" value="Reset">
</FORM>
</body>
</html>
How to Make Login Form in PHP

Save the php code with input05.php in htdocs folder.
Program 2
File Name: process05.php
Description: A simple program to check the username and password usage in program 1.
Open notepad type the following php code into notepad.
<?php
if (isset($_POST['Login'])) {
$user = $_POST['username'];
$pass = $_POST['password'];
 if ($user == "johans" && $pass == "123") {
echo "<h2>Login Successful</h2>";
 } else {
echo "<h2>Login Failed</h2>";
}
}
?> 
How to Make Login Form in PHP

Save the php code with the name process05.php in the htdocs folder.
Explanation of Programs 1 and 2
Program 1 will display a simple login form which consists of username and password input. Furthermore, the value inputted will be processed in program 2. If the username and password inputted correctly then the message will be displayed successfully (see picture) and if the login is wrong it will display an error message (see picture).
To run the login program open the browser then type http://localhost/input05.php in the address bar. Then the result is as follows.
How to Make Login Form in PHP
Program View

How to Make Login Form in PHP
Program View 1 If Login Successful

How to Make Login Form in PHP
Program View 2 If Login Fails

That is the tutorial on how to make login form in php that we can share. Hopefully these tutorials can add to our knowledge of php programming language. Learn also tutorial on How to Create Data Entry Form in PHP.

Comments