Is there a difference between javascript cookies and php cookies?
A cookie is just a file stored on the client computer, and it typically contains a name, value, and expiration. Cookies are sent within header of an HTTP page request, so they aren't immediately available (unless you use output buffering). Cookies are good for non-sensitive data, since they are easily found via the client browser settings.
Cookies can also be used in creating Session variables, which are stored on the server. In this case, the cookie value is an index that the server uses to identify its values. This is a better approach for more sensitive data, since only a "meaningless" value resides on the client computer.
With this in mind, Cookies and Session data (as well as GET and POST data) are Super Global variables, which means they can be used by both JavaScript and PHP. Again, the only catch is that cookies may not be immediately available, depending on how your script works and your output buffering settings.
HTTP Cookies are not a feature of PHP, nor a feature of Javascript : those are just programming languages that allow a developper to manipulate them.
The biggest difference between JS and PHP is that :
But cookies are still the same : they are defined as a standard -- see RFC 2965.
Still, note that modern browsers implement cookies that are not accessible from Javascript (see the httponly
option of setcookie) -- which means that, depending on the browser, and the way a cookie was set, it might not be accessible from Javascript.
This is a security measure -- and is not a difference between "js cookies" and "php cookies" : it's just a property of some cookies.
No, cookies are defined by an RFC spec.