Is it possible to create a cookie with javascript and then read it with PHP? And What about the other way around?
A:
Yes you can both set and read cookies on either side.
On the javascript side you'll need to parse the document.cookie
variable, but there are plenty of libs to do that (jQuery has a plugin to do so).
Chadwick
2010-07-07 23:06:47
Make sure that you understand the order of things. You obviously can't have php and javascript share a cookie on the same page load.
nute
2010-07-08 00:39:34
A:
There is a new parameter in the php "setcookie" function (from php 5.2.0) that you should be aware of: it is called "httponly". If set to true (by you), javascript won't be allowed to read the cookie's content. It helps prevent XSS attacks. More info on: http://php.net/manual/en/function.setcookie.php
Zaziffic
2010-07-08 13:08:36