Forum Moderators: coopster

Message Too Old, No Replies

Setting a cookie value at first, then overwrite cookie with value+1

         

Jeremy_H

5:11 pm on Mar 20, 2006 (gmt 0)

10+ Year Member



Hello,

I'm trying to create a special cookie.

If the user doesnt have this cookie, a cookie will be set equal to 1.

If the user does have this cookie set, the value will be read (and used further down in the script), and then that cookie will be overwritten with it's current value +1.

I've written the following script, but it's not working, and I think it might have something to do with the fact that 1 is trying to be added to a string, maybe?

if(isset($_COOKIE["count"])){$count==$_COOKIE["count"]+1;setcookie("count",$count,time()+604800);}else{setcookie("count","1",time()+604800);$count="1";}

echo ($count);

Thanks for any help.

Tastatura

5:29 pm on Mar 20, 2006 (gmt 0)

10+ Year Member



I am new to PHP so take this with a grain of salt…
In your code
$count==$_COOKIE["count"]+1;

you are using ‘==’ which, as I understand it, is a comparison operator (i.e you are comparing two values to see if they are equal). If I understood your script correctly, you want to assign new value to $count, in which case you should use ‘=’. If this presumtion is correct try something like this:

$count = ($_COOKIE["count"]+1);

HTH

Jeremy_H

5:57 pm on Mar 20, 2006 (gmt 0)

10+ Year Member



Tastatura, you're awesome!

That was exactly the problem!

Not only did that help me fix that one bug, but it also helped me fix a yet uncovered bug on the next line too!

Thanks