Link to home
Start Free TrialLog in
Avatar of maratmu
maratmu

asked on

Accessing a Cookie Value


 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
ASKER CERTIFIED SOLUTION
Avatar of saknarak
saknarak
Flag of Thailand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of y2kwacko
y2kwacko

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
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.