<?php
require_once('upper.php');
$error_msg='';
if(!isset($_COOKIE['LoginIdCookie'])){
if(isset($_POST['submit']))
{
require_once('database.php');
$LoginId=mysqli_real_escape_string($dbc,trim($_POST['LoginId']));
$Password=mysqli_real_escape_string($dbc,trim($_POST['Password']));
if((!empty($LoginId)) && (!empty($Password))){
$query="SELECT * FROM registration WHERE LoginId='$LoginId' AND Password=SHA('$Password') AND Flag='A'";
$result=mysqli_query($dbc,$query) or die('Not Connected');
if(mysqli_num_rows($result)==1)		
{
$row=mysqli_fetch_array($result);
setcookie('LoginIdCookie',$row['LoginId']);
//$home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index1.php';
header('Location: index1.php');
}
else{
echo 'Enter right UserName/Password combination or You may not approved yet. ';
echo '<a href="ForgetPassword.php">Can\'t access your account?"</a>';
}}
else{
echo' Fill all fields';
}
}}
?>
<html>
<title>Log In</title>
<body>
<?php
if(empty($_COOKIE['LoginIdCookie']))
{
echo $error_msg;
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ;?>" >
<div class="LoginValidator">
<fieldset>
<legend>
Log In</legend><table><tr><td>
<label for="username">User Name :</label><br/><br/></td>
<td><input type="text" name="LoginId"><br/><br/></tr>
<td><label for="password">Password :</label></td>
<td><head>
   <div id="divMayus" style="visibility:hidden">Caps Lock is on.</div>
   <SCRIPT language=Javascript>

function capLock(e){
 kc = e.keyCode?e.keyCode:e.which;
 sk = e.shiftKey?e.shiftKey:((kc == 16)?true:false);
 if(((kc >= 65 && kc <= 90) && !sk)||((kc >= 97 && kc <= 122) && sk))
  document.getElementById('divMayus').style.visibility = 'visible';
 else
  document.getElementById('divMayus').style.visibility = 'hidden';
}

</SCRIPT>
   </HEAD>

<input onkeypress='return capLock(event)' type="password" name="Password"><br/></td></tr></table>
<input type="submit" name="submit" value="Login" class="Login_button">
</fieldset>

</div>
</form>

<?php 
}
else{
echo 'You are logged in as '.$_COOKIE['LoginIdCookie'];
}
require_once('lower.php');
mysqli_close($dbc);
?>

HI friends..........
In above code when I enter wrong user name or password, it displays error msg properly but problem is that when i enter right user name and password instead to redirect to index1.php it displays LoginPage again..........
I think cookie is not created as well..........
I can't understand where is problem???????/
Plz help me....................

<?php
require_once('upper.php');
$error_msg='';
if(!isset($_COOKIE['LoginIdCookie'])){
if(isset($_POST['submit']))
{
require_once('database.php');
$LoginId=mysqli_real_escape_string($dbc,trim($_POST['LoginId']));
$Password=mysqli_real_escape_string($dbc,trim($_POST['Password']));
if((!empty($LoginId)) && (!empty($Password))){
$query="SELECT * FROM registration WHERE LoginId='$LoginId' AND Password=SHA('$Password') AND Flag='A'";
$result=mysqli_query($dbc,$query) or die('Not Connected');
if(mysqli_num_rows($result)==1)		
{
$row=mysqli_fetch_array($result);
setcookie('LoginIdCookie',$row['LoginId']);
//$home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index1.php';
header('Location: index1.php');
}
else{
echo 'Enter right UserName/Password combination or You may not approved yet. ';
echo '<a href="ForgetPassword.php">Can\'t access your account?"</a>';
}}
else{
echo' Fill all fields';
}
}}
?>
<html>
<title>Log In</title>
<body>
<?php
if(empty($_COOKIE['LoginIdCookie']))
{
echo $error_msg;
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ;?>" >
<div class="LoginValidator">
<fieldset>
<legend>
Log In</legend><table><tr><td>
<label for="username">User Name :</label><br/><br/></td>
<td><input type="text" name="LoginId"><br/><br/></tr>
<td><label for="password">Password :</label></td>
<td><head>
   <div id="divMayus" style="visibility:hidden">Caps Lock is on.</div>
   <SCRIPT language=Javascript>

function capLock(e){
 kc = e.keyCode?e.keyCode:e.which;
 sk = e.shiftKey?e.shiftKey:((kc == 16)?true:false);
 if(((kc >= 65 && kc <= 90) && !sk)||((kc >= 97 && kc <= 122) && sk))
  document.getElementById('divMayus').style.visibility = 'visible';
 else
  document.getElementById('divMayus').style.visibility = 'hidden';
}

</SCRIPT>
   </HEAD>

<input onkeypress='return capLock(event)' type="password" name="Password"><br/></td></tr></table>
<input type="submit" name="submit" value="Login" class="Login_button">
</fieldset>

</div>
</form>

<?php 
}
else{
echo 'You are logged in as '.$_COOKIE['LoginIdCookie'];
}
require_once('lower.php');
mysqli_close($dbc);
?>

HI friends..........
In above code when I enter wrong user name or password, it displays error msg properly but problem is that when i enter right user name and password instead to redirect to index1.php it displays LoginPage again..........
I think cookie is not created as well..........
I can't understand where is problem???????/
Plz help me....................

Its amazing friends ........
I got zero replies on 2 days.........
wow what a forum?????////////

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.