Help With PHP And Cookies
Posted: Wed Jul 26, 2006 11:55 am
I've been having a hell of a time trying to figure out how to implement what I thought was a simple PHP script to save a username in a cookie so it would be displayed each time the user returns. Here is the code:
And the contents of cook.php...
I have seen plenty of example online of using forms and cookies to save information, but I keep getting an error saying "Cannot modify header information - headers already sent". I've read a little about what this means, but I've seen many different explanations and none seemed to help. Any help would really be appreciated. Thanks.
Code: Select all
<?php
if (isset($_COOKIE['megacookie']))
{
echo "Hello, ".$_COOKIE['megacookie']."!";
}
else
{
include('cook.php');
if (isset($_GET['names']))
{
setcookie("megacookie",$_GET['names'],time()+60*60*24*365);
}
}
?>Code: Select all
<form action="reflex.php" method="get">
Go Away:<input type="text" name="names" size="10" maxlength="20" value="">
<input type="submit" value="Press">
</form>I have seen plenty of example online of using forms and cookies to save information, but I keep getting an error saying "Cannot modify header information - headers already sent". I've read a little about what this means, but I've seen many different explanations and none seemed to help. Any help would really be appreciated. Thanks.