In this post, I will share with you a PHP Login Script and provide you with a knowledge of how to create login page in PHP which you dynamic facilities as like below.
In this post, I will give you an idea of how to create PHP login welcome page with MySQL database. This will help you for creating tables & form values. As a beginner, you can do this without any hassle by following the PHP script.
This post helps you to create Username, Password and next pages. It has been updated with MySQL.
Read Similar Article:
1. Facebook Like Profile Able To Edit With Jquery
2. How To Check if WiFi is connected Or Disconnected
3. How To Run Computer Management MSC & Some Useful Run Commands
4. Using Jquery File Upload: Ajax Image Upload Without Refreshing
5. Login with Facebook and Twitter Easy Program With Codes
Login Page In PHP
Now we give a look how to create login page in PHP with MySQL Database.
Database:
CREATE TABLE admin
(
id INT PRIMARY KEY AUTO_INCREMENT,
username VARCHAR(30) UNIQUE,
passcode VARCHAR(30)
);
Config.php
You Just Use These Code For Database configuration.
<?php
define(‘DB_SERVER’, ‘localhost’);
define(‘DB_USERNAME’, ‘username’);
define(‘DB_PASSWORD’, ‘password’);
define(‘DB_DATABASE’, ‘database’);
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>
Login.php
Contains PHP and HTML code For Login Form.
<?php
include(“config.php”);
session_start();
if($_SERVER[“REQUEST_METHOD”] == “POST”)
{
// username and password sent from Form
$myusername=mysqli_real_escape_string($db,$_POST[‘username’]);
$mypassword=mysqli_real_escape_string($db,$_POST[‘password’]);
$passwordSecure=md5($mypassword);
$sql=”SELECT id FROM admin WHERE username=’$myusername’ and passcode=’$passwordSecure'”;
$result=mysqli_query($db,$sql);
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
$active=$row[‘active’];
$count=mysqli_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
{
session_register(“myusername”);
$_SESSION[‘login_user’]=$myusername;
header(“location: welcome.php”);
}
else
{
$error=”Your Login Name or Password is invalid”;
}
}
?>
<form action=”” method=”post”>
<label>UserName :</label>
<input type=”text” name=”username”/><br />
<label>Password :</label>
<input type=”password” name=”password”/><br/>
<input type=”submit” value=” Submit “/><br />
</form>
lock.php
Session verification Codes. If you have no session value page then helps redirect to login.php
<?php
include(‘config.php’);
session_start();
$user_check=$_SESSION[‘login_user’];
$ses_sql=mysqli_query($db,”select username from admin where username=’$user_check’ “);
$row=mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);
$login_session=$row[‘username’];
if(!isset($login_session))
{
header(“Location: login.php”);
}
?>
welcome.php
<?php
include(‘lock.php’);
?>
<body>
<h1>Welcome <?php echo $login_session; ?></h1>
</body>
logout.php
SignOut Option.
<?php
session_start();
if(session_destroy())
{
header(“Location: login.php”);
}
?>
These are the PHP login script for login page in PHP. Hopefully, you can be done this web project successfully by following this post.
If you have any query don’t avoid the comment section. I will try to give your answer. Share this post on your social wall with your all buddies.