print more than 1 cookie

Asked

Viewed 58 times

0

I’m having a doubt here and am unable to resolve since I am beginner in php.

I want to retrieve cookies and print on the screen a certain value that corresponds to the cookie, but 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 didn’t work

  • I could not understand very well, you are only declaring 1 cookie, which other you want to show?

1 answer

2


Use a foreach to return all cookies. This way you will be able to identify all the names and values of the 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)), "/");
  • Thank you so much for your help. vlw msm

Browser other questions tagged

You are not signed in. Login or sign up in order to post.