PHP cookies problem, works in Firefox not in other browser

后端 未结 5 516
深忆病人
深忆病人 2021-01-05 12:22

I\'ve a problem with setting cookies in php. I\'ve to say that I\'m not very experienced with php, so maybe is a very stupid problem.

I\'ve an ajax rating system tha

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-05 12:56

    Are you setting the cookie on the exact same URL? If you're using $_SERVER['HTTP_HOST'] then one browser may set it for http://example.com while another may set it on http://www.example.com. If you visit the alternate version the cookie won't be set.

    To quote the PHP docs:

    The domain that the cookie is available. To make the cookie available on all subdomains of example.com then you'd set it to '.example.com'. The . is not required but makes it compatible with more browsers. Setting it to www.example.com will make the cookie only available in the www subdomain.

    So try setting '.yoursite.com' as the domain.

    Other things to try:

    • $name is the only required parameter in the setcookie function - try skipping everything after $expire and see if it works.
    • Try setting an $expire value a long way into the future. Maybe there is something on your computer or the server causing a time issue?
    • Have you checked in your browser if the cookie is definitely being set? There should be a way to list every cookie set. Set the cookie and check your browser.

提交回复
热议问题