Accessing a Cookie Value

maratmu
maratmu used Ask the Experts™
on

 Hi,
        I am setting number of cookies in one of my scripts and when i run an another script to access those using print_r($_COOKIE); i get this display :

        Array ( [coeff] => 3 [rate] => 3 [hardening] => 3 [cmodulus] => 5 [cminor] => 5 [ccthe] => 5 [cdensity] => 5 [pcbmodulus] => 6 [pcbminor] => 6 [pcbcthe] => 6 [pcbdensity] => 6 [pmmodulus] => 7 [pmminor] => 7 [pmcthe] => 7 [pmdensity] => 7 [cmmodulus] => 8 [cmminor] => 8 [cmcthe] => 8 [cmdensity] => 8 [smesh] => VISCO107 )


     But if i access the cookie using $_COOKIE['coeff'], i don't get any display, how to access the cookies which are in Array above with the respective name inside the
 
     square bracket like [coeff] is the cookie i set in my earlier script with value 3.

     Please help me
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
you are corrected.

but try this script

<?php
print_r($_COOKIE);
echo "===========> ".$_COOKIE['coeff'];
?>

if you not see, try again with this script
(to check space padding in name)
<?php
print_r($_COOKIE);
foreach ( $_COOKIE as $key => $val )
{
  echo "Key [".$key"] => [".$val."]<br>\n";
}
?>

if still not try next comment :~~~~

Commented:
maratmu,

You may want to check into the HTTP_COOKIE_VARS array as well.

Quoting from http://us2.php.net/manual/en/function.setcookie.php
-------------------------------------------------------------------------------------------------------------------------------------------------------------


Note that the value portion of the cookie will automatically be urlencoded when you send the cookie, and when it is received, it is automatically decoded and assigned to a variable by the same name as the cookie name. To see the contents of our test cookie in a script, simply use one of the following examples:



<?php
// Print an individual cookie
echo $_COOKIE["TestCookie"];
echo $HTTP_COOKIE_VARS["TestCookie"];

// Another way to debug/test is to view all cookies
print_r($_COOKIE);
?>
 
-------------------------------------------------------------------------------------------------------------------------------------------------------------


Regards,
Kevin

Commented:
Your example should work fine.  Is the array you printed the entire contents of the $_COOKIE array?   Or is it further down somewhere...
Are you referencing the $_COOKIE['coeff'] on the same page as the print_r($_COOKIE) statement?  Check case sensitivity & spelling also.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial