Monday, March 10, 2014

PHP Login System Source Codes

Today, we are going to make a simple login system with php codes.

Steps:
1. At First we will create a simple login form by html
2. we will put php codes there to check whether the user name correct or not correct.

Let's start:
first create the html form like below image:






<form  action="" method="POST">
<h3>Login Panel</h3>
<hr/>


<input type="email" class="e1" name="email" >

<input type="password" class="p1" name="password">


<input type="submit" name="submit" class="b1" value ="Log In" />



</form>










This will create your login form and the next step we are going to take is putting php codes into it.

Lets' check the php codes:


<?php
if(isset($_POST['email'])){

session_start();
include('../db.php');
$qry = mysql_query("SELECT * FROM YOUR_DATABASE_TABLE");
if(!$qry) die("<h6 style='color: #ff0000;'>Error is ".mysql_error()."</h6>" );

$u = array(); //keep username
$p = array(); //keep password
$htmlu = htmlentities(mysql_real_escape_string($_POST['email']));
$htmlp = htmlentities(mysql_real_escape_string(md5($_POST['password'])));

$i=0;
while($row = mysql_fetch_array($qry))
{
$u[] = $row['email'];
$p[] = $row['password'];
$i++;
}


// login check
for( $j=0; $j <= sizeof($u); $j++ ) {
if( $u[$j] == $htmlu && $p[$j] == $htmlp) {
header ('Location: ./index.php');
}
}

echo "<h2>Incorrect</h2>";


}

?>



Place the php code into the <form> and the let it work into localhost.

that is how you can make a login system.

1 comment:

  1. Titsanium Connecting Rod - Titanium Connecting Rod
    Titsanium Connecting Rod · Titanium Connection Rod · Titanium Connection Rod · Titanium Connection titanium hair trimmer Rod used ford escape titanium · 2020 ford ecosport titanium Titsanium titanium trimmer Connection Rod · Titsanium Connection Rod · how to get titanium white octane Titsanium Connection Rod.

    ReplyDelete