Login page in php web application is created using sessions. Session array is used for storing user data on server side.Here is session array
Here if form for php login page.login_view.php
 <h1>Login Now</h1>

<form method=”post” id=”moduleDetail”
action=”signin_view.php<?php echo ($isEditing ? “?id=$userId” : “”); ?>”>
<span id=”validation_msg” style=”color:red”></span>
<label for=”user_name”>User Name</label>
<input id=”user_name” name=”user_name” type=”text” value=”<?php echo $userDetail[‘user_name’]; ?>”/>
<span id=”user_nameInfo”></span>
<label for=”password”>Password</label>
<input type=”password” id=”password” name=”password” value=””/>
<span id=”passwordInfo”></span>
<input id=”add” name=”login” type=”button” value=”Login” onclick=”validateLogin();”/>
From is validated and submited to server for validation of user.
Here is code for server side validation for user
//form submitted
//$user_name = “user_name ='”.$_POST[‘user_name’].”‘ AND “;
//$password = “password = ‘”.$_POST[‘password’].”‘”;

$arrUser = array(
//insert employee
$result = $signUpDal->validateLogin($_POST[‘user_name’],$_POST[‘password’]);

echo $result;
ValidateLogin function code is here
 public function validateLogin($user_name, $password)
$qry = “SELECT u.user_id,u.user_name,u.password, u.email, u.role FROM users u WHERE user_name= ‘”.$user_name.”‘ AND password = ‘”.$password.”‘”; //u.user_id=$userId”;
//foreach($param as $key=>$val){
//    $qry = $qry.$val;
$res = $this->conn->executeQuery($qry);

$users = array();
if (($row = mysql_fetch_assoc($res))) {
$users = $row;
if($users[‘user_name’] == $user_name && $users[‘password’] == $password)
$result= 1;
else {
$result = 0;
return $result;

If the result is 1 then this user is stored to session
Above code that is red colored is to store validated user in session.
$_SESSION[‘user_name’]=$_POST[‘user_name’]; // storing user to session.

Leave a Reply

Your email address will not be published. Required fields are marked *