print more than 1 cookie

0

I have a question here and I can not solve it since I am a beginner in php.

I want to retrieve cookies and print on the screen a certain value that corresponds to the cookie, however I can only print 1 cookie.

Página que eu estou pegando o cookie 
<?php
    setcookie("Nome",$Valor,(time() + (7 * 24 * 3600 )));
    $_COOKIE["Nome"];
?>

Página que eu estou exibindo os cookie
<?php
    $Test = $_COOKIE["Nome"];

    print_r($Test);
?>

I already tried echo instead of "print_r" and it did not work

    
asked by anonymous 18.05.2017 / 21:03

1 answer

2

Use a foreach to return all cookies. This way you will be able to identify all the names and values of cookies and hence be able to retrieve the ones you need for your application.

foreach ($_COOKIE as $key => $value) {
  print($key.' - '.$value.'<br>');
};
  

By default, the cookie can be used in the directory where it was created and in its subdirectories. If we indicate "/" the cookie will be valid within the entire domain.

setcookie("Nome",  $Valor, (time() + (7 * 24 * 3600)), "/");
    
18.05.2017 / 21:21