darkcarnival Posted August 8, 2006 Share Posted August 8, 2006 hi,i want to improve the ratng system i have on my site.right now no matter what item you vote for the same cookie will be created overwritting the last value, and i want to change that.what i want to so is name the cookie based on the id of the item.i tried to that but the cookie isnt being read. it'll clamin the cookie doesnt exist even though it was creayted successfully.cant show any code since i had to revert to to the old system to prevent any mass rating that it would cause. Quote Link to comment https://forums.phpfreaks.com/topic/16931-cookie-question/ Share on other sites More sharing options...
bltesar Posted August 8, 2006 Share Posted August 8, 2006 how are you setting the cookie. If you don't set the expire parameter, then the cookie will expire when the session is ended. Consequently, upon return to the site, the cookie will not exist.setcookie ( string name [, string value [, int expire [, string path [, string domain [, bool secure]]]]] )time()+60*60*24*30 (for the expire parameter) will set the cookie to expire in 30 days. If not set, the cookie will expire at the end of the session (when the browser closes). for more info see http://us3.php.net/manual/en/function.setcookie.php Quote Link to comment https://forums.phpfreaks.com/topic/16931-cookie-question/#findComment-71299 Share on other sites More sharing options...
bpops Posted August 8, 2006 Share Posted August 8, 2006 You are creating the cookie before any HTML tags are printed correct? Quote Link to comment https://forums.phpfreaks.com/topic/16931-cookie-question/#findComment-71350 Share on other sites More sharing options...
darkcarnival Posted August 9, 2006 Author Share Posted August 9, 2006 i use ob and ob_end_flush ;)and yes the session limit is set to last 24 hoursjust to give you some code that i can remember:[code] $currtime = time() + (86400); setcookie("metalrate$id", $id, $currtime, "/", "metalstation1.com", 0);[/code]that is not the problem, though this part is:[code]if(isset($_COOKIE['metalrate$id']) == $id){$voted = true;}else{$voted = false;}[/code]any ideas on this? Quote Link to comment https://forums.phpfreaks.com/topic/16931-cookie-question/#findComment-71552 Share on other sites More sharing options...
Corona4456 Posted August 9, 2006 Share Posted August 9, 2006 Try:[code]if(isset($_COOKIE['metalrate'.$id]) == $id)[/code]Instead of:[code]if(isset($_COOKIE['metalrate$id']) == $id)[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16931-cookie-question/#findComment-71554 Share on other sites More sharing options...
ToonMariner Posted August 9, 2006 Share Posted August 9, 2006 why create multiple cookies????? all those cookies will be sent separatelyhave a look at this [url=http://uk.php.net/manual/en/function.setcookie.php]http://uk.php.net/manual/en/function.setcookie.php[/url] and pay particular attention to example 3. Quote Link to comment https://forums.phpfreaks.com/topic/16931-cookie-question/#findComment-71555 Share on other sites More sharing options...
darkcarnival Posted August 9, 2006 Author Share Posted August 9, 2006 no they wont sadly.in further test of this method it overwrote the last value. i realized that after a user figure it out and exploited the rating system.so making a new cookie for each rate is needed to ensure users dont abuse the rating system or at least not so often as one has or can. Quote Link to comment https://forums.phpfreaks.com/topic/16931-cookie-question/#findComment-71613 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.