Re: setcookie

From: Date: Wed, 12 Mar 2008 13:17:14 +0000
Subject: Re: setcookie
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-271356@lists.php.net to get a copy of this message
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

« previous php.general (#271356) next »