Agent M wrote:
New to PHP. Im trying to set a cookie but for some reason it wont work.
The code is inside a Submit button and happens after I have read the MySQL
database and succesfully retrieved the record. For some reason the cookie is
not created.
(snip) What can be wrong?
Has the client /sent/ the cookie to the server?
Only /received/ cookies are available in the $_COOKIE (or equivalent)
variable.
Try this:
<?php
echo '<p>cookie not set yet!</p>';
if (isset($_COOKIE['test'])) echo '<p>Cookie is <b>', $_COOKIE['test'], '</b></p>';
setcookie('test', 'true');
echo '<p>cookie has been set!</p>';
if (isset($_COOKIE['test'])) echo '<p>Cookie is <b>', $_COOKIE['test'], '</b></p>';
?>
Now open this page in your browser and see what happens ... then refresh
the browser and see what happens
The first time you open the page, the client will not have send the
cookie (it doesn't have it); the second time the client sends the cookie
(once, before the script starts -- it's the web server job to make it
available to the script) and you'll see it in both echo's
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--