Still fighting setcookie
| From: | John Hinton | Date: | Sun, 27 Mar 2005 18:11:43 +0000 |
| Subject: | Still fighting setcookie | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-211671@lists.php.net to get a copy of this message | ||
OK, I created this most simplistic script..
---- Begin Script-------------------------------------------
<?php
if(isset($value))
{
setcookie("mycookie",$value);
}
define (Login, 0);
define (DataReturn, 1);
function login() {
echo "<form ACTION=\"$_SERVER[PHP_SELF]?action=1\" METHOD=\"post\" ENCTYPE=\"multipart/form-data\">";
echo "Type value: <input name=\"value\" type=\"text\">";
echo "<input name=\"submit\" type=\"submit\">";
echo "</form>";
}
function datareturn(){
print_r($_COOKIE);
echo " is the \$_COOKIE data";
}
if (empty ($action))
$action = 0;switch ($action) { case Login: login(); break; case DataReturn:
datareturn();
break;
default:
die ("Unknown action code ($action)");
}
?>
----End Script------------------------
I would expect the return on action=1 to report the set cookie, but instead, it has no data. If I then reload the browser, the cookie appears. How can I get the cookie to set without this reload? What am I missing?
Thanks a bunch...
John Hinton