How can I set a cookie and then redirect in PHP?

后端 未结 5 976
孤街浪徒
孤街浪徒 2020-11-29 06:19

After doing a bit of processing, I want to set a cookie value to user input and then redirect them to a new page. However, the cookie is not getting set. If I comment out

5条回答
  •  醉话见心
    2020-11-29 07:08

    How are you testing if the cookie is set? Cookies are available on the next page after they are set.

    Common Pitfalls:

    Cookies will not become visible until the next loading of a page that the cookie should be visible for. To test if a cookie was successfully set, check for the cookie on a next loading page before the cookie expires. Expire time is set via the expire parameter. A nice way to debug the existence of cookies is by simply calling print_r($_COOKIE);.

提交回复
热议问题