Balmung-San Posted September 30, 2006 Share Posted September 30, 2006 Okay, I've got this script that's [i]supposed[/i] to check for the existance of a cookie, wether or not the user exists based on the value of the cookie, and whether the password(contained in another cookie) is valid. However, it seems that it's not working correctly when the cookie doesn't exist. Any help?[code] if(isset($_COOKIE['hd_amv_user'])) { if(!isset($_COOKIE['hd_amv_pass'])) { setcookie("hd_amv_user","Guest",(time()+24*3600*9999)); setcookie("hd_amv_pass","",(time()+24*3600*9999)); } else { $passCheckSql = mysql_query("SELECT * FROM amv_users WHERE username='".$_COOKIE['hd_amv_user']."'"); if(mysql_num_rows($passCheckSql) > 1 || mysql_num_rows($passCheckSql) == 0) { setcookie("hd_amv_user","Guest",(time()+24*3600*9999)); setcookie("hd_amv_pass","",(time()+24*3600*9999)); } else { $passCheck = mysql_fetch_array($passCheckSql); if(strcasecmp($_COOKIE['hd_amv_pass'], $passCheck['password']) != 0) { setcookie("hd_amv_user","Guest",(time()+24*3600*9999)); setcookie("hd_amv_pass","",(time()+24*3600*9999)); } } } } else { setcookie("hd_amv_user","Guest",(time()+24*3600*9999)); setcookie("hd_amv_pass","",(time()+24*3600*9999)); }[/code] Quote Link to comment https://forums.phpfreaks.com/topic/22615-cookies-wont-set/ Share on other sites More sharing options...
Balmung-San Posted September 30, 2006 Author Share Posted September 30, 2006 Sorry for the double post, I fixed that one, but now my logout script doesn't work. I do the setcookie() calls first thing in my script, set them both to blank with an expire time of time()-3600. Shouldn't that erase the cookies?Oh, and I run the above script after I supposedly erased them. Quote Link to comment https://forums.phpfreaks.com/topic/22615-cookies-wont-set/#findComment-101581 Share on other sites More sharing options...
HuggieBear Posted October 1, 2006 Share Posted October 1, 2006 [quote author=Balmung-San link=topic=110097.msg444440#msg444440 date=1159651163]my logout script doesn't work. I do the setcookie() calls first thing in my script, set them both to blank with an expire time of time()-3600. Shouldn't that erase the cookies?[/quote]As you haven't posted your code for expiring the cookies, I have to guess what it looks like, but one piece of advice is make sure you you set it with the same amount of parameters.From the manual...[quote]Cookies must be deleted with the same parameters as they were set with. If the value argument is an empty string, or FALSE, and all other arguments match a previous call to setcookie, then the cookie with the specified name will be deleted from the remote client.[/quote]RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/22615-cookies-wont-set/#findComment-101801 Share on other sites More sharing options...
Balmung-San Posted October 1, 2006 Author Share Posted October 1, 2006 Ah, that'd do it. I was setting with 5 parameters, and trying to erase with 3. Quote Link to comment https://forums.phpfreaks.com/topic/22615-cookies-wont-set/#findComment-101851 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.