How to create a Login page with PHP and MySQL
Contents
In this Post We Will Explain About is How to create a Login page with PHP and MySQL With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Creating a User Login System with PHP and MySQL Example
In this post we will show you Best way to implement How to create a Login page with PHP and MySQL, hear for How to Create a Login Page in PHPwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.
PHP Login Page Example Steps
Hello, Are you looking for simple Auth module PHP login script, in this post I want to Learn how to create a simple scripts PHP login with welcome page (Dashboard) using MySQL database.here This will explain you step by step creating user tables and managements, posting form some values and storing data and destroying data the session values. This login post has been some updated with mysqli.
Step 1 : Database
MySQL simple userMst table columns Like as a id, clientName, passcode.
CREATE TABLE userMst ( id INT PRIMARY KEY AUTO_INCREMENT, clientName VARCHAR(30) UNIQUE, passcode VARCHAR(30) );
Step 2 : Config.php
Simple Database configuration file.
<?php define('DB_SERVER', 'YOUR_localhost'); define('DB_USERNAME', 'YOUR_username'); define('DB_PASSWORD', 'YOUR_password'); define('DB_DATABASE', 'YOUR_database_name'); $db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE); ?>
Step 3 : Login.php
Simple steps to Contains PHP and HTML Source code.
<?php include("config.php"); session_start(); if($_SERVER["REQUEST_METHOD"] == "POST") { // clientName and password sent from Form $my_clientName=mysqli_real_escape_string($db,$_POST['clientName']); $mypassword=mysqli_real_escape_string($db,$_POST['password']); $sql="SELECT id FROM userMst WHERE clientName='$my_clientName' and passcode='$mypassword'"; $data_result=mysqli_query($db,$sql); $row=mysqli_fetch_array($data_result,MYSQLI_ASSOC); $active=$row['active']; $count=mysqli_num_rows($data_result); // If data_result matched $my_clientName and $mypassword, table row must be 1 row if($count==1) { session_register("my_clientName"); $_SESSION['login_user']=$my_clientName; header("location: welcome.php"); } else { $error="Your USER Login Name or Password is wrong"; } } ?> <form action="" method="post"> <label>Eneter Your UserName :</label> <input type="text" name="clientName"/><br /> <label>Eneter Your Password :</label> <input type="password" name="password"/><br/> <input type="submit" value=" Submit "/><br /> </form>
Step 4 : lock.php
Simple Session verification. If no any create session value page redirect to simple main login.php
<?php include('config.php'); session_start(); $session_check=$_SESSION['login_user']; $ses_sql=mysqli_query($db,"select clientName from userMst where clientName='$session_check' "); $data_row=mysqli_fetch_array($ses_sql,MYSQLI_ASSOC); $user_login_ses=$data_row['clientName']; if(!isset($user_login_ses)) { header("Location: login.php"); } ?>
Step 5 : welcome.php
<?php include('lock.php'); ?> <body> <h1>Pakainfo.com Welcome <?php echo $user_login_ses; ?></h1> </body>
logout.php
and then Last step to SignOut all the session Destroy the session value.
<?php session_start(); if(session_destroy()) { header("Location: login.php"); } ?>
I hope you have Got What is PHP Login Page Example with Demo And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.
I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I’m a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.