Computer Science Canada

COOKIE [ SOLVED ]

Author:  Amailer [ Thu Mar 04, 2004 7:19 pm ]
Post subject:  COOKIE [ SOLVED ]

Okay, suppose i have this.

a variable
$variable = 'text.'$id_from_db;

i set a cookie for the $variable
setcookie($variable, $count, time()+60*60*24);


now what i want to do is..... to check if the cookie is set or not i.e
$COOKIE[$variable];

that doens't seem to work though, how would i get a cookie by using a variabel ( i.e $COOKIE[$variable]; ) if you know what i mean...

Author:  wtd [ Thu Mar 04, 2004 8:19 pm ]
Post subject: 

Try using $_COOKIE instead of $COOKIE.

Author:  Amailer [ Thu Mar 04, 2004 8:26 pm ]
Post subject: 

wouldn't that be just as a normal variable? also how does this solve my problem :S maby iv not explained it well enough.

I have set a cookie:

code:

$cookie_name = 'gfxpro.'.$d2['d2_id'];

....
$count = 1;
setcookie($cookie_name, $count, time()+60*60*24);


now i want to check if that cookie isset so i did this:
code:

if( isset($_COOKIE[$cookie_name]) ) {
...
}


but that doesn't work is there another way around this?

Author:  wtd [ Thu Mar 04, 2004 8:31 pm ]
Post subject: 

RTFM Smile

http://ca.php.net/manual/en/features.cookies.php

Author:  Amailer [ Thu Mar 04, 2004 8:43 pm ]
Post subject: 

ya but hmm but it's not working... i don't think it's setting cookie right with the name...

Author:  wtd [ Thu Mar 04, 2004 9:09 pm ]
Post subject: 

It should be noted that changes in cookies won't be noticeable until the page is reloaded.

Author:  Amailer [ Thu Mar 04, 2004 9:10 pm ]
Post subject: 

actually i checked, it is setting the cookie but the
if (!isset($HTTP_COOKIE_VARS[$cookie_name])) {

doesn't seem to be working, why!


problem solved:
i think it had to do with the . in the name... hmm idk i removed it and it worked lol...


: