Forum Moderators: coopster

Message Too Old, No Replies

cookie isset test

         

kumarsena

8:18 pm on Jan 10, 2004 (gmt 0)

10+ Year Member



hey,

how can i test if a cookie is present?
i need to assign a value in the cookie to a var, but if cookies are disables then have a default value.

thanks for any help
kumar

kumarsena

8:20 pm on Jan 10, 2004 (gmt 0)

10+ Year Member



would somethign liket his make sense?

<?php

$HTTP_COOKIE_VARS['var'] = $var;

if (isset($var))
{

$var2 = $var

}

else { $var = default}

?>

justageek

8:32 pm on Jan 10, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just test the cookie var. Remember also that you cannot test the cookie until the user goes to another page or refreshes the current one.

<?php

if(isset($HTTP_COOKIE_VARS['var'])){;
$var = $HTTP_COOKIE_VARS['var'];
}else{
$var = default_value;
}

?>

This will also prevent the error you would get trying to assign the cookie value that might not exist to a var.

JAG

kumarsena

8:52 pm on Jan 10, 2004 (gmt 0)

10+ Year Member



cool thanks