httponly是微软对cookie进行的扩展。 这主要是解决用户饼干可能被偷的问题。
我们登录某家银行的网站后,服务器会在我们的浏览器上写饼干。 下次访问另一个页面时,浏览器会自动传递cookie,这样您登录一次就可以查看登录后需要查看的所有内容。
也就是说,实际上,所有登录状态都是构建在cookie上的! 假设有人得到了我们登录后的饼干,那就有暴露个人信息的危险!
当然,其他人怎么才能得到客户的饼干? 那必然是恶意人的程序在浏览器里运行! 如果是现在在天上飞的流氓软件,那就没办法了。 httponly也不是为了解决这种情况,而是为了解决js在浏览器中访问cookie的问题。
在php上设置httponly
session.cookie _ http only=1(or true )
whetherornottoaddthehttponlyflagtothecookie,whichmakesitinaccessibletobrowserscriptinglanguagessuchasjavascript。
; 33558 PHP.net/session.cookie-http only
session.cookie_httponly=
说明: http://PHP.net/manual/zh/session.configuration.PHP # ini.session.cookie-secure
session.cookie_httponly boolean
marksthecookieasaccessibleonlythroughthehttpprotocol.thismeansthatthecookiewon ' tbeaccessiblebyscriptinglanguages, suchas JavaScript.thissettingcaneffectivelyhelptoreduceidentitytheftthroughxssattacks (althoughitisnotsupportedbyallbrowsers
Cookie操作函数setcookie和setrawcookie函数也添加了第七个参数作为HttpOnly选项。 打开的方法如下。
------------- -请参阅
setcookie(ABC )、) test )、NULL、NULL、NULL、TRUE );
setrawcookie(ABC )、) test )、NULL、NULL、NULL、NULL、TRUE );
------------- -请参阅
在thinkphp中,在配置和惯例文件convention.php .中
' COOKIE_HTTPONLY'=',//Cookie httponly设置