I am having problem with setting up a php cookie, what am I doing wrong? Below I added 3 examples which I tried. Next to the examples, I also tried to change the time which the cookie is working but is all did not work.
Evert time I get the notworking variable indicating that the cookie is not set, do you know what am I doing wrong? Thanks!
Example from: http://www.w3schools.com/php/showphp.asp?filename=demo_func_http_setcookie
$works="It is working!";
$notworking="Not working";
$name=20;
setcookie($name_cookie, $name, time() + 100000, '/');
if (isset($_COOKIE[$name_cookie])){
echo $works;
}
else{
echo $notworking;
}
Example from:
http://php.net/manual/en/function.setcookie.php
And
Query about PHP cookie
Example 2:
$works="It is working!";
$notworking="Not working";
$name=20;
setcookie("name_cookie", "name", time() + 100000, '/');
if (isset($_COOKIE["name_cookie"])){
echo $works;
echo $_COOKIE[$name_cookie];
echo $name_cookie;
}
else{
echo $notworking;
}
Example 3
$works="It is working!";
$notworking="Not working";
$name=20;
setcookie("name_cookie", $name, time() + 100000, '/');
if (isset($_COOKIE["name_cookie"])){
echo $works;
}
else{
echo $notworking;
}