Answer the question
In order to leave comments, you need to log in
Why is the cookie not being read?
Why the code doesn't work
<?php
setcookie("cookiewithdomain", "ralph", null, null, null, true, true);
print $_COOKIE["cookiewithdomain"];
?>
Answer the question
In order to leave comments, you need to log in
if(isset($_GET['q'])){
setcookie("cookiewithdomain", "ralph", null, null, null, false, true);
}
print $_COOKIE["cookiewithdomain"];
Because setcookie sends a cookie header to the browser. In order for the cookie to arrive on the server (and the print line to work "correctly"), you need to turn to the page again.
Maxim Vlasov suggested separating the moment of creating and receiving cookies. On his script, refer to the page with the q parameter. This will set the cookie (send it to the browser). Then, without a parameter to it, the page will show the cookie received from the browser.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question