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.

> If I really have to work out what they should be, and then set them up,
> before issuing any diagnostics, etc, it will make life decidely more 
> complicated. (I
> assume that I can set several cookies using successive calls to setcookie()?)

Yes, each one with a differente name.

>
> I was also somewhat surprised to find that a cookie is used to implement 
> sessions. Does
> this place any limitations on using both sessions and cookies in the same 
> program?
>

No. The cookie in PHP that implements session is by default called
PHPSESSID. As long as your other cookies are named differently, you
should be fine.

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

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

Reply via email to