开发者

PHP + Javascript - Read/Write Cookies

Is it possible to create a cookie with javascript and then read it with PHP? And What about the other 开发者_如何学Cway around?


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜