Jump to content

Archived

This topic is now archived and is closed to further replies.

darkcarnival

cookie question

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
You are creating the cookie before any HTML tags are printed correct?

Share this post


Link to post
Share on other sites
i use ob and ob_end_flush  ;)

and yes the session limit is set to last 24 hours

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

Share this post


Link to post
Share on other sites
Try:
[code]if(isset($_COOKIE['metalrate'.$id]) == $id)[/code]

Instead of:
[code]if(isset($_COOKIE['metalrate$id']) == $id)[/code]

Share this post


Link to post
Share on other sites
why create multiple cookies????? all those cookies will be sent separately

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.