Jump to content


Photo

cookie question


  • Please log in to reply
6 replies to this topic

#1 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 08 August 2006 - 06:40 PM

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.

#2 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 08 August 2006 - 06:47 PM

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/m...n.setcookie.php

#3 bpops

bpops
  • Members
  • PipPipPip
  • Advanced Member
  • 232 posts

Posted 08 August 2006 - 07:52 PM

You are creating the cookie before any HTML tags are printed correct?

#4 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 09 August 2006 - 01:34 AM

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:

            $currtime = time() + (86400);
            setcookie("metalrate$id", $id, $currtime, "/", "metalstation1.com", 0);

that is not the problem, though this part is:

if(isset($_COOKIE['metalrate$id']) == $id){
$voted = true;
}else{
$voted = false;
}

any ideas on this?

#5 Corona4456

Corona4456
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts
  • LocationEl Paso, TX

Posted 09 August 2006 - 01:36 AM

Try:
if(isset($_COOKIE['metalrate'.$id]) == $id)

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

What is the CoronaMatrix?

#6 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 09 August 2006 - 01:40 AM

why create multiple cookies????? all those cookies will be sent separately

have a look at this http://uk.php.net/ma...n.setcookie.php and pay particular attention to example 3.
follow me on twitter @PHPsycho

#7 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 09 August 2006 - 04:21 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users