PHP Can't read cookies?

前端 未结 4 1485
轮回少年
轮回少年 2021-01-22 12:03

I like to use PHP to see if a cookie PHPSID27258STATUS is present with the value COMPLETE en if so do stuff.

In google chrome (in Options) I ca

4条回答
  •  渐次进展
    2021-01-22 12:09

    You mention that the cookie is set by a program running in its own sub-directory. You don't mention whether the cookie itself is set to be in that sub-directory, but I suspect this is where your problem is.

    If a cookie is set to a path, then it will only be accessible to pages within that path. This behaviour is described in the PHP setcookie() manual page.

    When you're setting cookies from a page within a sub-directory, then in order for the cookie to be accessible to the whole site, setcookie() needs to be called with the optional path parameter set to "/".

    You state that the cookie is being set by LimeSurvey. I don't know this software, but you should be able to look at the source and see whether it's using the path parameter when it sets the cookie. If not, your best option would be to modify it so that it does. Then the cookie will be accessible to the whole site. (It would be quite understandable if the LineSurvey developers had chosen not to set it for the whole site, because it would allow the software to be run as a more isolated entity from anything else on the site).

提交回复
热议问题