Re: Cookies & sessions

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

 



On Tue, Jan 19, 2010 at 10:06:26PM +1100, clancy_1@xxxxxxxxxxxx wrote:

> 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? 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()?)

Session variables are available throughout your session. Cookie
variables are only available if you read them into variables you can
access. Changes to session variables will the flushed to the server when
your page is terminated. Cookie variables are flushed to disk if you
make the appropriate *_cookie() function call, and even then I don't
know if this is actually echoed to disk until your page is terminated.

> 
> 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?

I don't believe so. If I'm not mistaken, session values are stored on the
server, not on the client. What's stored on the client is the session
ID.

Please bear in mind my understanding of cookies is fragmentary, and I
hope someone else will write in to correct any incorrect statements I've
made.

Paul

-- 
Paul M. Foster

-- 
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