how to unset cookie in PHP?

前端 未结 6 465
旧时难觅i
旧时难觅i 2020-12-02 01:31

I need to figure out how to unset this cookie. Everything I tried so far has failed.

This is how I am currently unsetting it and it doesn\'t seem to work.

         


        
6条回答
  •  猫巷女王i
    2020-12-02 02:15

    The solution to this problem was that the I needed to set the correct path to unset the cookie since I was unsetting it from a different file that I originally set it in.

    I found out which path I needed to use for the unset by looking for the cookie inside my browser cookies, and once I found the cookie inside my browser, the path was listed near the cookie. So I then set the path to the cookie like so:

    setcookie("user_id", $user_id, time() - 1, "/social_learning/site_pages");
    

    The last parameter is the path. And it worked.

    My original setcookie looks like this:

    setcookie("user_id", $user_id, time() + 7200, "");
    

提交回复
热议问题