Possible Duplicate:
Javascript cook开发者_C百科ies vs php cookies
Since php scripts are executed on the server, does that mean that php cookies will behave differently from javascript cookies? Is so, what will the differences be? Thank you.
There is no such thing as PHP cookies. There are HTTP cookies which are stored on the client browser. PHP allows you to set and read cookies by using emitting the Set-Cookie HTTP header, but all that is standard HTTP protocol stuff, nothing PHP related. There is one thing though : cookies emitted with the HttpOnly flag are not accessible by client scripts.
Cookies are always stored on the client.
However, a cookie created through a HTTP header (i.e. by server-side code) can have the HTTPOnly flag, preventing JavaScript from acessing its value.
HTTP cookies are small pieces of data, which the browser sends to the server on each request. They are usually set by the Cookie
Header of an earlier HTTP response, and stored on the client (i.e. browser) for some time (depending on the cookie type and the client's configuration).
PHP's cookie-related functions are only an interface to this feature of the HTTP protocol.
Normally those cookies can also be accessed (both read and changed) by client-side JavaScript (and browser plugins), but as already said by ThiefMaster, this access can be prevented by the HTTPOnly
flag.
精彩评论