How to access cookie values on different paths of the same domain using PHP?

后端 未结 5 968
暖寄归人
暖寄归人 2020-12-11 16:34

Can a parameter of path be added to $_COOKIE[]?

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-11 17:21

    yes, it's the 4th argument, but you will only be able to access the cookie if it was set using a path that the current directory resides in.

    that's confusing... here it is from php:

    The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain . If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain . The default value is the current directory that the cookie is being set in.

    http://php.net/manual/en/function.setcookie.php

    You access it like any other cookie. It will become available in $_COOKIE if the script has access to it.

提交回复
热议问题