Is it possible to create a cookie with javascript and then read it with PHP? And What about the other way around?
2 Answers
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).
1 Comment
Nathan H
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.
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