PHP cookie set in second refresh page

前端 未结 5 459
耶瑟儿~
耶瑟儿~ 2020-12-10 08:10

i want to use cookie in web page and i want to use it for save any optional variables. but after use setcookie and refresh page isset()

5条回答
  •  伪装坚强ぢ
    2020-12-10 08:35

    When you set a cookie, it is sent to the browser. The next time the browser then sends a request for a page, it sends the cookie information back and the page can make use of it.

    1. Browser visits page (login or something similar), and sends NO cookie data.
    2. Server sets cookie (which means including them in the header of the HTTP reply).
    3. Browser visits page and sends back cookie data.
    4. Server can see cookie data and make use of it.

    To fix it, redirect the user to the page where you want to display the data after the cookie has been set, instead of simply displaying the page. This way you can make use of the cookie data.

提交回复
热议问题