<?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…
Sir,
My original code properly works on my local system i.e. in windows XP but when i upload it in my Linux Server it creates problem…
I don’t know what is wrong???////
Sir, I run your code and I didn’t got ant cookie.
Are session_start(); is applicable for sessions and cookies both???
Anyway it also not works…
Any suggestion???/
I don’t think that a cookie can be set if there is any prior output, and once set, it cannot be correctly read until the page has been reloaded.
Here’s what the setcookie() documentation has to say about it.
Like other headers, cookies must be sent before any output from your script (this is a protocol restriction).
Once the cookies have been set, they can be accessed on the next page load
So, an effective solution is to check for byte-order markers and other potential output beforehand, and to ensure that the cookie is not attempted to be read in the same page load that it has been set.