ankit.pandeyc012 Posted December 25, 2010 Share Posted December 25, 2010 <?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.................... Quote Link to comment https://forums.phpfreaks.com/topic/222622-cookie-is-not-created-and-page-is-not-redirect-properly/ Share on other sites More sharing options...
dragon_sa Posted December 25, 2010 Share Posted December 25, 2010 try to echo $row['LoginId'] after the query and see if it gives you a result also the php manual says to put cookie name in double quotes. eg setcookie("LoginIdCookie",$row['LoginId']); Quote Link to comment https://forums.phpfreaks.com/topic/222622-cookie-is-not-created-and-page-is-not-redirect-properly/#findComment-1151312 Share on other sites More sharing options...
ankit.pandeyc012 Posted December 25, 2010 Author Share Posted December 25, 2010 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??????//// Quote Link to comment https://forums.phpfreaks.com/topic/222622-cookie-is-not-created-and-page-is-not-redirect-properly/#findComment-1151314 Share on other sites More sharing options...
dragon_sa Posted December 25, 2010 Share Posted December 25, 2010 This will show you if the cookie is set [print_r($_COOKIE);/php] Quote Link to comment https://forums.phpfreaks.com/topic/222622-cookie-is-not-created-and-page-is-not-redirect-properly/#findComment-1151316 Share on other sites More sharing options...
ankit.pandeyc012 Posted December 25, 2010 Author Share Posted December 25, 2010 Ohhhhh I got the main problem....... Cookie is not setting in linux server actually but i don't know why it is so????????? Is there anyone?????? Quote Link to comment https://forums.phpfreaks.com/topic/222622-cookie-is-not-created-and-page-is-not-redirect-properly/#findComment-1151317 Share on other sites More sharing options...
PFMaBiSmAd Posted December 25, 2010 Share Posted December 25, 2010 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); Quote Link to comment https://forums.phpfreaks.com/topic/222622-cookie-is-not-created-and-page-is-not-redirect-properly/#findComment-1151336 Share on other sites More sharing options...
.josh Posted December 25, 2010 Share Posted December 25, 2010 you said it works on localhost but on on a remote server...is your database and connection info the same on the remote server as it is on your localhost, same user/pw stored in db, etc..? Quote Link to comment https://forums.phpfreaks.com/topic/222622-cookie-is-not-created-and-page-is-not-redirect-properly/#findComment-1151410 Share on other sites More sharing options...
ankit.pandeyc012 Posted December 26, 2010 Author Share Posted December 26, 2010 Sir, All passwords are set well and if I did this mistake then it should displayed an error. But there is no error ............. Quote Link to comment https://forums.phpfreaks.com/topic/222622-cookie-is-not-created-and-page-is-not-redirect-properly/#findComment-1151483 Share on other sites More sharing options...
ankit.pandeyc012 Posted December 26, 2010 Author Share Posted December 26, 2010 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................ Quote Link to comment https://forums.phpfreaks.com/topic/222622-cookie-is-not-created-and-page-is-not-redirect-properly/#findComment-1151485 Share on other sites More sharing options...
dragon_sa Posted December 26, 2010 Share Posted December 26, 2010 what if you try this on a blank php page on the linux server <?php $value='my test cookie'; setcookie("TestCookie", $value); print_r($_COOKIE); ?> See if this prints out your newly set cookie Quote Link to comment https://forums.phpfreaks.com/topic/222622-cookie-is-not-created-and-page-is-not-redirect-properly/#findComment-1151490 Share on other sites More sharing options...
PFMaBiSmAd Posted December 26, 2010 Share Posted December 26, 2010 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.) Quote Link to comment https://forums.phpfreaks.com/topic/222622-cookie-is-not-created-and-page-is-not-redirect-properly/#findComment-1151504 Share on other sites More sharing options...
ankit.pandeyc012 Posted December 27, 2010 Author Share Posted December 27, 2010 what if you try this on a blank php page on the linux server <?php $value='my test cookie'; setcookie("TestCookie", $value); print_r($_COOKIE); ?> See if this prints out your newly set cookie Thanks for reply. but your above code displays "Array()". I think cookie is not generated yet. Plz help........ Quote Link to comment https://forums.phpfreaks.com/topic/222622-cookie-is-not-created-and-page-is-not-redirect-properly/#findComment-1151693 Share on other sites More sharing options...
ankit.pandeyc012 Posted December 27, 2010 Author Share Posted December 27, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/222622-cookie-is-not-created-and-page-is-not-redirect-properly/#findComment-1151694 Share on other sites More sharing options...
PFMaBiSmAd Posted December 27, 2010 Share Posted December 27, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/222622-cookie-is-not-created-and-page-is-not-redirect-properly/#findComment-1151695 Share on other sites More sharing options...
ankit.pandeyc012 Posted December 27, 2010 Author Share Posted December 27, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/222622-cookie-is-not-created-and-page-is-not-redirect-properly/#findComment-1151717 Share on other sites More sharing options...
dragon_sa Posted December 27, 2010 Share Posted December 27, 2010 instead of print_r($_COOKIE); use echo $_COOKIE["TestCookie"]; see if that gives you the value we set in the example code I posted Quote Link to comment https://forums.phpfreaks.com/topic/222622-cookie-is-not-created-and-page-is-not-redirect-properly/#findComment-1151729 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.