On Tue, 19 Jan 2010 09:12:17 -0200, bsfaja...@gmail.com (Bruno Fajardo) wrote:

>2010/1/19  <clanc...@cybec.com.au>:
>> I am trying for the first time to use cookies. The manual contains the 
>> statement "Cookies
>> are part of the HTTP header, so setcookie() must be called before any output 
>> is sent to
>> the browser."
>>
>> When I first started using sessions, I was alarmed to read a very similar 
>> statement about
>> sessions, but I soon found that if I started my program with the statement
>> "session_start();" I could then set up, access, modify or clear any session 
>> variable at
>> any time in my program. This is enormously useful, as I can put the session 
>> handling at
>> any convenient point in my program, and can precede them with diagnostics if 
>> I need to.
>>
>> However I have almost immediately found that while I appear to be able to 
>> read cookies at
>> any time, I cannot set them when I would like to. Is there any similar trick 
>> which will
>> work with cookies?
>

>The only trick is that you have to call setcookie() before any output
>is sent to the browser, just like the session_start() behavior.
> ......

Thank you all for your suggestions.  Unfortunately I have already tried this, 
and it
doesn't work for me (I am running PHP: 5.1.6).  I have only tested this on my 
own PC, but
if it doesn't work here, I would be very surprised if it would work on the 
remote server.

Index.php starts:

        <?php //;V;;;                           Cypalda/Index.php   Printed: 

        session_start ();
        setcookie ();
        setcookie ('user_id', 'Wilma*Witgenstein', time()+3600);

And this produces the following output:

Warning: setcookie() expects at least 1 parameter, 0 given in
D:\Websites\cypalda.com\index.php on line 4

Warning: Cannot modify header information - headers already sent by (output 
started at
D:\Websites\cypalda.com\index.php:4) in D:\Websites\cypalda.com\index.php on 
line 5

It is interesting to note that the second diagnostic is generated because the 
first
diagnostic is taken to have initiated the headers. I think I can live with this
limitation, but this diagnostic is a warning of the hassles I am likely to face 
if I
cannot find a way around it.


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

Reply via email to