I tried many ways to set a cookie, but when I get the cookie the value's not set. My code is placed before the <!DOCTYPE html>
:
<?php
$url = explode('/', $_GET['url']);
$ref = $url[1];
$cookie_name = "refid";
$cookie_value = $ref;
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/", "", 0);
?>
The $url[1]
is set, I can see it in print_r()
the problem is getting the cookie from a different page the calling code is:
<?php
if (!isset($_COOKIE['refid'])) {
echo "<br/>Cookie named refid is not set!";
} else {
echo "<br/>Cookie refid is set!<br>";
echo "Value is: " . $_COOKIE['refid'];
}
?>
Please help to resolve my problem.
Cookie refid is set!
"; echo "Value is: " . $_COOKIE['refid']; } ?>` – Arshad Shaikh May 31 '17 at 05:09