Cookies on localhost with explicit domain

前端 未结 21 1813
[愿得一人]
[愿得一人] 2020-11-22 04:17

I must be missing some basic thing about cookies. On localhost, when I set a cookie on server side and specify the domain explicitly as localhost (or .localhost). t

21条回答
  •  时光说笑
    2020-11-22 05:01

    By design, domain names must have at least two dots; otherwise the browser will consider them invalid. (See reference on http://curl.haxx.se/rfc/cookie_spec.html)

    When working on localhost, the cookie domain must be omitted entirely. Just setting it to "" or NULL or FALSE instead of "localhost" is not enough.

    For PHP, see comments on http://php.net/manual/en/function.setcookie.php#73107.

    If working with the Java Servlet API, don't call the cookie.setDomain("...") method at all.

提交回复
热议问题