如何在PHP中设置使用HttpOnly Cookie [英] How do you set up use HttpOnly cookies in PHP

查看:179
本文介绍了如何在PHP中设置使用HttpOnly Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在我的 PHP应用程式中设定Cookie为 HttpOnly cookies

How can I set the cookies in my PHP apps as HttpOnly cookies?

推荐答案


  • 对于您的Cookie ,请参阅此答案。

  • 对于 PHP自己的会话Cookie (默认情况下, PHPSESSID ),请参阅 @ euhiemf的回答

    • For your cookies, see this answer.
    • For PHP's own session cookie (PHPSESSID, by default), see @euhiemf's answer
    • setcookie() setrawcookie() 功能,介绍了 httponly 参数,回到在PHP 5.2.0的黑暗时代,使这个很好和容易。根据语法

      The setcookie() and setrawcookie() functions, introduced the httponly parameter, back in the dark ages of PHP 5.2.0, making this nice and easy. Simply set the 7th parameter to true, as per the syntax

      b

      setcookie(    $name, $value, $expire, $path, $domain, $secure, $httponly )
      setrawcookie( $name, $value, $expire, $path, $domain, $secure, $httponly )
      

      输入 NULL 用于希望保留为默认值的参数。
      您还可以考虑是否应该设置 secure 参数。

      Enter NULL for parameters you wish to remain as default. You may also want to consider if you should be setting the secure parameter.

      可能使用旧的,较低级的 header() 函数:

      It is also possible using the older, lower-level header() function:

      header( "Set-Cookie: name=value; httpOnly" );
      

      这篇关于如何在PHP中设置使用HttpOnly Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆