Reputation: 4584
I don't want to allow getting cookie from other page ! I have been searched on internet but not really found or may be I don't know how to mention that case .How can I manage that ! I want to get null in test2.php
but get cookie in test.php
?
test.php
<?php
setcookie("acc_id", "23A", time() + 3600, '/');
header("test.php");
var_dump($_COOKIE); // 'acc_id' => string '23A' (length=3)
?>
test2.php
<?php
var_dump($_COOKIE); // 'acc_id' => string '23A' (length=3)
Upvotes: 1
Views: 41
Reputation: 4360
You can use the $path
parameter in the setcookie syntax.
setcookie("acc_id", "23A", time() + 3600, '/test.php');
Now if you try print_r($_COOKIE['acc_id']);
from your test2.php, it will show you Undefined Index, which means the cookie is not set for that page.
Upvotes: 2