How to view Cookie on another page

Asked

Viewed 28 times

0

I have the code below:

php cookie.

$d1 =  "27/07/2017"; 
$d2 =  "27/07/2017"; 

setcookie("d1",$d1, (time() + (3 * 24 * 3600)));
setcookie("d2",$d2, (time() + (3 * 24 * 3600)));

$data1 = $_COOKIE["d1"];
$data2 = $_COOKIE["d2"];

?>

I want to display Cookie on this other page, but I can’t:

index php.

<?php

$data1 = $_COOKIE["d1"];
$data2 = $_COOKIE["d2"];

echo "Período informado: $data1 - $data2";

?>

The following error appears:

Notice: Undefined index: D1
Notice: Undefined index: D2

  • 1

    Try setting the fourth parameter of setcookie as "/".

  • That’s what I was missing. Thanks Anderson!

  • https://answall.com/questions/200325/problema-com-cookies-no-php/200333#200333

No answers

Browser other questions tagged

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