Jump to content

Cookie is not created and Page is not redirect properly....


ankit.pandeyc012

Recommended Posts

<?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....................

Link to comment
Share on other sites

For debugging purposes, add the following two lines of code immediately after the line with your first opening php tag, and tell us if any php detected errors are displayed -

 

ini_set("display_errors", "1");
error_reporting(-1);

 

Sir it not displayed any error.........

As I say it properly works on my local computer but when upload it in my linux server it creates problem.. I already checked username and password of database................

Link to comment
Share on other sites

I'm going to guess that your code is actually redirecting to index1.php, but that index1.php is redirecting back to the page you posted in this thread.

 

Have you actually checked in your bowser if the cookie exists and what value is in it? I suspect it is getting created with an empty() value and the code is doing what it is supposed to be doing (skipping the login code if the cookie isset() but displaying the login form if the value is empty().) You need to check what $row['LoginId'] actually contains. Either it is a value that the empty() function considers empty OR your column LoginId does not exist (possibly because you are on a case-sensitive operating system and the capitalization in your table is not exactly LoginId.)

Link to comment
Share on other sites

I'm going to guess that your code is actually redirecting to index1.php, but that index1.php is redirecting back to the page you posted in this thread.

 

Have you actually checked in your bowser if the cookie exists and what value is in it? I suspect it is getting created with an empty() value and the code is doing what it is supposed to be doing (skipping the login code if the cookie isset() but displaying the login form if the value is empty().) You need to check what $row['LoginId'] actually contains. Either it is a value that the empty() function considers empty OR your column LoginId does not exist (possibly because you are on a case-sensitive operating system and the capitalization in your table is not exactly LoginId.)

 

 

Thanks Sir,

What you said is right but i think it is problem of cookie because below code displays "Array()".

<?php
$value='my test cookie';
setcookie("TestCookie", $value);
print_r($_COOKIE);
?>

I want to tell I have same database in my local compuetr also.

Previously, same program runs on linux server properly but not now...............

Now what I have to do?????

Help me plzzzzzzzzzzzzzz

Link to comment
Share on other sites

Did you refresh the page with the code on it that dragon_sa posted, because the $_COOKIE variable is set when the browser sends the cookie with the HTTP request, not when you execute a setcookiei() statement.

 

Any chance you have disabled cookies in your browser for the domain you are testing this on?

 

Link to comment
Share on other sites

Did you refresh the page with the code on it that dragon_sa posted, because the $_COOKIE variable is set when the browser sends the cookie with the HTTP request, not when you execute a setcookiei() statement.

 

Any chance you have disabled cookies in your browser for the domain you are testing this on?

 

Sir,

I upload this code. After that I try to login by login page and then after I execute dragon_sa code and it again displays "Array()"...

thx for replying but I don't get solution yet.........

Help plzzzzzzzzzzzzz

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.