Skip to main content

How to Create a secure login panel with PHP & Mysql using parameters and session

Secure Login with PHP & Mysql

How to Create a secure login panel with PHP & Mysql

Requirement: you need an Apache and MySQL Server database on your device
If your computer has xampp or wamp or mamp or lamp that's great otherwise you need to install Apache and MySQL server

Create a database login

Run this query :


CREATE TABLE admin (
id INT(6) AUTO_INCREMENT PRIMARY KEY,
uname VARCHAR(30) NOT NULL,
upass VARCHAR(30) NOT NULL
);
INSERT INTO `admin` (`id`, `uname`, `upass`) VALUES (NULL, 'admin', 'admin1993');

That means you set your username =  admin and password = admin1993






Login Page: login.php


<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Login Getway</title>
<link rel="stylesheet" href="http://fontawesome.io/assets/font-awesome/css/font-awesome.css" type="text/css">
<style>
*
{
margin:0px;
padding:0px;
font-family:arial;
}
body
{
background:#DAECF3;
}
hr
{
background:#012D41;
border:none;
height:10px;
}
#logarea
{
height:250px;
border-radius:5px;
width:400px;
padding:20px;
background:rgba(255,255,255,1.00);
position:absolute;
top:0px; bottom:0px; left:0px; right:0px;
margin:auto;
-webkit-box-shadow: 0px 1px 1px 1px rgba(0,0,0,0.15);
-moz-box-shadow: 0px 1px 1px 1px rgba(0,0,0,0.15);
box-shadow: 0px 1px 1px 1px rgba(0,0,0,0.15);
}
h1
{
text-align:center;
font-weight:normal;
color:#012D41;
padding:10px;
font-size:24px;
border-bottom:1px solid #012D41;
width:300px;
margin:auto;
}
form
{
padding:20px 40px;
}
form input[type='text'],form input[type='password']
{
padding:10px;
margin-bottom:20px;
width:295px;
font-size:18px;
border-radius:5px;
border:none;
background:#DAECF3;
color:rgba(81,81,81,1.00);
text-align:center;
}
button
{
padding:10px 20px;
background:#012D41;
color:rgba(255,255,255,1.00);
border:none;
border-radius:5px;
}
button:nth-child(1)
{
background:#FF616C;
}
#logarea p
{
position:absolute;
bottom:10px;
left:0px;
width:100%;
text-align:center;
}
#logarea span
{
position:absolute;
bottom:-10px;
left:0px;
background:#012D41;
width:100%;
color:rgba(255,255,255,1.00);
text-align:center;
height:10px;
}
.fa-refresh
{
animation: loadingpw 1s linear infinite;
}
@keyframes loadingpw{
0%{ transform:rotate(0deg)}
100%{transform:rotate(360deg)}
}
</style>
</head>
<body>
<hr>
<div id="logarea">
<h1>Login</h1>
    <form method="post" action="?tyringTologing" enctype="multipart/form-data">
    <input type="text" name="username" placeholder="username">
        <input type="password" name="password" placeholder="password">
     
        <center>
        <button type="submit" name="loginbutn">
        <i class="fa fa-unlock" aria-hidden="true"></i> Login
        </button>
        <button type="reset">
        <i class="fa fa-repeat" aria-hidden="true"></i> Retype
        </button>
        </center>
    </form>
    <p>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$database = "login";
$conn = mysqli_connect($servername, $username, $password,$database);
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
session_start();
if(isset($_POST['loginbutn']))
{
$username = mysqli_real_escape_string($conn, $_POST['username']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
$sqlQuery = "SELECT uname, upass FROM admin WHERE uname=? AND upass=?";
$stmt = mysqli_prepare($conn, $sqlQuery);
if($stmt)
{
mysqli_stmt_bind_param($stmt,"ss", $username, $password);
mysqli_stmt_bind_result($stmt, $accUsername, $accPassword);
mysqli_stmt_execute($stmt);
mysqli_stmt_fetch($stmt);
if(!empty($accUsername) AND !empty($accPassword))
{
echo 'Please wait while we redirect you <i class="fa fa-refresh"></i>';
$_SESSION["standerdUse"] = $accUsername;
header("location: index.php");
}
else
{
echo 'Please check your Username and Password';
}
mysqli_stmt_close($stmt);
}
else
{
echo 'Something is worng';
}
}
?>
    </p>
    <span></span>
</div>


</body>
</html>
Dashboard: index.php


<?php
session_start();
if(!$_SESSION['standerdUse'])
{
header('Location:login.php');
echo "<script> window.open('login.php','_self') </script>";
}
$servername = "localhost";
$username = "root";
$password = "";
$database = "login";
$conn = mysqli_connect($servername, $username, $password,$database);
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Dash Board</title>
</head>
<body>
<?php
echo "<h1 align='center'>".$_SESSION['standerdUse']." you are successfully come in your admin panel</h1>";
?>
    <center><a href="?logout">Logout</a></center>
    <?php
if(isset($_GET['logout']))
{
echo "your session logout";
session_destroy();
header('Location:login.php');
echo "<script> window.open('login.php','_self') </script>";
}
?>
</body>
</html>

If you want to download project zip Click to download.


Comments

Popular posts from this blog

Windows all version product key free

Product key for window vista : Vista | Ultimate | Acer | 3YDB8-YY3P4-G7FCW-GJMPG-VK48C Vista | Ultimate | Advent | 39MVW-K8KKQ-BGJ9B-24PMW-RYQMV Vista | Ultimate | Alienware | 7QVFM-MF2DT-WXJ62-XTYX3-P9YTT Vista | Ultimate | Asus | 6F2D7-2PCG6-YQQTB-FWK9V-932CC Vista | Ultimate | Dell | 2QBP3-289MF-9364X-37XGX-24W6P Vista | Ultimate | DixonsXP | 6JPQR-4G364-2B7P7-83FXW-DR8QC Vista | Ultimate | Gateway | 6P8XK-GDDTB-X9PJQ-PYF36-G8WGV Vista | Ultimate | Hedy | 7R2C3-DWCBG-C8G96-MPT8T-K37C7 Vista | Ultimate | HP | 23CM9-P7MYR-VFWRT-JGH7R-R933G Vista | Ultimate | Lenovo | 24J6Q-YJJBG-V4K4Q-2J8HY-8HBQQ Vista | Ultimate | OQO | C4QGV-XHYYT-9PW8R-DCFTQ-FBD6M Vista | Ultimate | Toshiba | 33G3W-JY3XQ-CQQ7C-TG96R-R6J6Q Vista | Ultimate | Sony | 2KKTK-YGJKV-3WMRR-3MDQW-TJP47 Vista | Ultimate | Stone | GVV4P-RQXD7-X9XKB-M2G9H-C93VM Vista | Ultimate | Velocity Micro | 9BKKK-7Y888-MHD67-HHXTB-332K9 Vista | Business | Acer | 2TJTJ-C72D7-7BCYH-FV3HT-JGD4F Vista | Bus...

How to access Xampp or Wamp with Skype in one client system.

Xampp or Wamp with Skype in one computer system Note: many people tell me their problem that they can't use xampp or wamp with skype in same computer.  Problem is the port problem. in computer and device application software run with the help of OS port. xampp and skype run as default same port (80). the solution is if I change the skype or xampp application the both software run smoothe and the same time. Now steps here. open skype > go to tools > then Option > goto advance > connection Click to save and now you can use both applications in side by side on one computer.