Home >>MySQL Tutorial >PHP MySQL Secure Login Page
Login page is basically a page having several fields that the user provide in order to get access of the home page of that site. if there is a previously registered user whose details are stored in the database and that particular user want to login then the details provided by him on the login page are cross checked with the fields in the database respectively. if the details are found to be correct the user is considered to be a valid user.
As we already know that http is a stateless protocol and it doesn't identify any previous user, that's why we maintain the session for that particular user.
<?php $con=mysqli_connect("localhost","root","","test") or die(mysqli_error()); ?>
<?php session_start(); if(isset($_POST['signIn'])) { if($_POST['id']=="" || $_POST['pwd']=="") { $err="fill your id and passwrod first"; } else { $d=mysqli_query($con,"SELECT * FROM userinfo where user_name='{$_POST['id']}'"); $row=mysqli_fetch_object($d); $fid=$row->user_name; $fpass=$row->password; if($fid==$_POST['id'] && $fpass==$_POST['pwd']) { $_SESSION['sid']=$_POST['id']; header('location:HomePage.php'); } else { $err="invalid id or pass"; } } } ?>
<form method="post"> <table width="323" border="1"> <tr> <font color="#FF0000"><?php echo $err; ?></font> <th width="171" scope="row">Enter your id </th> <td width="136"> <input type="text" name="id" /> </td> </tr> <tr> <th scope="row">Enter your password </th> <td> <input type="password" name="pwd"/> </td> </tr> <tr> <th colspan="2" scope="row"> <input type="submit" value="SignIn" name="signIn"/> <a href="http://localhost/Mailserver/index.php?chk=4">SignUp</a> </th> </tr> </table> </form>