oMIKEo Posted July 27, 2006 Share Posted July 27, 2006 Hi, Can anyone tell me why this code isnt working, the login script creates a cookie, then redirects you to a profile page, that page first checks to see if the cookie exists otherwise kicks you to a login page.I added print_r($_COOKIE); onto the profile page to see what cookies are being passed to that page, it comes back with none :S[code]<?phpinclude "config.php";if( (!$username) or (!$password) ){ header("Location:$HTTP_REFERER"); exit(); }$conn=@mysql_connect("$db_host","$db_username","$db_password") or die("Could not connect");$rs = @mysql_select_db($db_main,$conn) or die("Could not select database");$sql="select * from bn_profile where band_email=\"$username\" and password=\"$password\"";$rs=mysql_query($sql,$conn) or die("Could not execute query" . mysql_error());$num12 = mysql_num_rows($rs);if($num12!=0){ setcookie("UN", $username, time()+3600, "/", ".breakingtuneshosting.com", 0);header("Location:profile.php"); exit(); }else{ header("Location:$HTTP_REFERER"); exit(); }?>[/code]Also if i echo $num12; i get a value of 1 so it should be creating the cookie.Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/15834-cookies-issue/ Share on other sites More sharing options...
realjumper Posted July 27, 2006 Share Posted July 27, 2006 [code]$sql="select * from bn_profile where band_email=\"$username\" and password=\"$password\"";[/code]Doesn't look right to me...shouldn't it be....[code]$sql="select * from bn_profile where band_email=$username and password=$password";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15834-cookies-issue/#findComment-64829 Share on other sites More sharing options...
king arthur Posted July 27, 2006 Share Posted July 27, 2006 No it shouldn't - you must surround string values with quotes, although most people probably use single ones.I would suggest first trying the call to setcookie with only the first three parameters.Or could it be that as you are doing a redirect straight away, there is no opportunity for the browser to send the cookie? Someone will be along in a minute who knows more than me about such things! Quote Link to comment https://forums.phpfreaks.com/topic/15834-cookies-issue/#findComment-64834 Share on other sites More sharing options...
realjumper Posted July 27, 2006 Share Posted July 27, 2006 Okay, sorry if I missled with my comment...I have never done it with double quotes and a backslash...as you say, single quotes is the norm, which I omitted to add Quote Link to comment https://forums.phpfreaks.com/topic/15834-cookies-issue/#findComment-64835 Share on other sites More sharing options...
oMIKEo Posted July 27, 2006 Author Share Posted July 27, 2006 Thanks guys,Ive tried using just: setcookie("UN", $username, time()+3600);but that didnt help (if thats what you meant)The thing is ive used this exact script on a number of other hosting providers and its worked fine which is why im so confused and really need some help.... thanks Quote Link to comment https://forums.phpfreaks.com/topic/15834-cookies-issue/#findComment-64856 Share on other sites More sharing options...
king arthur Posted July 28, 2006 Share Posted July 28, 2006 Ok, have you set your browser's security settings to notify you when it recieves a cookie? Then at least you can tell if it's a problem writing the cookie or reading it back. Quote Link to comment https://forums.phpfreaks.com/topic/15834-cookies-issue/#findComment-65084 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.