2

Is it possible to create a cookie with javascript and then read it with PHP? And What about the other way around?

1
  • Your bio is looking great!. Look I have copied it. Commented Dec 6, 2012 at 15:14

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.