Re: setcookie

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Wolf wrote:


Tim Daff wrote:
Hi,

I am learning PHP, I am trying to set a simple cookie:

<html>
    <head>
        <title>Cookies</title>
    </head>
    <body>
               <?php setcookie('test', 45, time()+(60*60*24*7)); ?>
           </body>
</html>

Firefox is returning this error:

Warning: Cannot modify header information - headers already sent by (output started at /Users/Daff/Sites/php_sandbox/cookies.php:7) in /Users/Daff/Sites/php_sandbox/cookies.php on line 7

I have googled this and can't find out what I am doing wrong. Any help you could give me would be much appreciated.

Tim

 <?php setcookie('test', 45, time()+(60*60*24*7)); ?>
 <html>
     <head>
         <title>Cookies</title>
     </head>
     <body>



     </body>
 </html>

Cookies HAVE to be at the top of the page... You output ANYTHING else and you get the error you wound up getting.

Wolf



If you're not sure if data has already been sent to the client (I ran into an included file having a space after >?) you can use http://us3.php.net/manual/en/function.headers-sent.php before you call setcookie();

If nothing else it'll help with diagnosing this error when you run into it again.

--
Ray Hauge
www.primateapplications.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux