I have a problem I can not solve: I'm unable to read a cookie value in my theme.
I have a form that allows you to choose a country from a list.
It sends it to a PHP page that generates a cookie whose value is the country code, like this:

setcookie ('cookiePays', $_POST['selectPays'], time () + 432000);
$cookiePaysChoisi = $_COOKIE['cookiePays'];

Then we are redirected to the site home page.
Also I have a module that is supposed to read the contents of the cookie and pass it in a global variable, like this:

global $cookPays;
if (isset ($_COOKIE['cookiePays'])) {
   $cookPays = $_COOKIE['cookiePays'];
else {
$cookPays = "xx";

Finally, in page.tpl.php, I try to show that famous country code:

<h3 style="position: absolute; background: white;"> SELECTED COUNTRIES: <?php global $cookPays; echo $cookPays ?></ h3> 

Well, I ALWAYS get the result: SELECT COUNTRY: XX!
The cookie is never read.
While in the php page that reads the form, I send me the result of the cookie by email, to make sure it is correct, that is!
Note that I have tried with a session variable, and I get the same result.
I also tried to read the result in html.tpl.php, in a function in template.php, always the same!
Whenever I'm in Drupal, I can not read my cookie. I searched a long time on the Internet I found nothing there something I'm missing!

Does anyone have a solution or idea? Is there something special I have to to to read cookies or session variable, or is the problem only in my Drupal installation ?

Thank you in advance!


meybeck’s picture

Actually, i can read the $_COOKIE variable, but my cookie is not inside.
When I create it, in another page, I can access to its value if I'm not in my Drupal site.
But when I visit my Drupal website homepage, my cookie is destroyed ! It's not in the $_COOKIE variable anymore !
Has somebody got an idea ? Would be great !

meybeck’s picture

OK I just forgot the path parameter to make the cookie available in all directories. That's all folks.