Re: [PHP] setcookie

This is a discussion on Re: [PHP] setcookie within the PHP General forums, part of the PHP Programming Forums category; > <body> > > <?php setcookie('test', 45, time()+(60*60*24*7)); ?> from the doc: &...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-12-2008
Jean-Christophe Roux
 
Posts: n/a
Default Re: [PHP] setcookie

> <body>
>
> <?php setcookie('test', 45, time()+(60*60*24*7)); ?>


from the doc:
"Cookies are part of the HTTP header, so setcookie() must be called before any output is sent to the browser. This is the same limitation that header() has."
http://ca.php.net/cookies


----- Original Message ----
From: Tim Daff <timdaff@gmail.com>
To: php-general@lists.php.net
Sent: Wednesday, March 12, 2008 8:48:59 AM
Subject: [php] setcookie

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





__________________________________________________ __________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

Reply With Quote
  #2 (permalink)  
Old 03-12-2008
Shiplu
 
Posts: n/a
Default Re: [PHP] setcookie

Even you cant put a space before <?php tag.

the following code will throw the same error.
| <?php
| setcookie();
| ?>
Because I prepend a space for each line

But this will be okay
|<?php
| setcookie();
| ?>

This is a very common mistake and very very hard to find.


On Wed, Mar 12, 2008 at 7:53 AM, Jean-Christophe Roux <jcxxr@yahoo.com>
wrote:

> > <body>
> >
> > <?php setcookie('test', 45, time()+(60*60*24*7)); ?>

>
> from the doc:
> "Cookies are part of the HTTP header, so setcookie() must be called
> before any output is sent to the browser. This is the same limitation
> that header() has."
> http://ca.php.net/cookies
>
>
> ----- Original Message ----
> From: Tim Daff <timdaff@gmail.com>
> To: php-general@lists.php.net
> Sent: Wednesday, March 12, 2008 8:48:59 AM
> Subject: [php] setcookie
>
> 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
>
>
>
>
>
>
> __________________________________________________ __________________________________
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile. Try it now.
> http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
>


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:17 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0