开发者

PHP + Javascript - Read/Write Cookies

开发者 https://www.devze.com 2023-01-06 05:26 出处:网络
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.

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

精彩评论

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

关注公众号