PHP cookie value works only after 2 page loads

后端 未结 1 1181
孤城傲影
孤城傲影 2021-01-28 20:26

I know this might be an extremely beginner level question but I am just a month into PHP so please bear with me. I am trying to set a cookie in a WordPress blog. The cookie rece

1条回答
  •  南笙
    南笙 (楼主)
    2021-01-28 21:06

    When you set a cookie, it doesn't populate $_COOKIE on that page load, as that variable is loaded from what the browser sends you. A workaround for that would be to set $_COOKIE['name'] = $name; after your setcookie statement - but that does not guarantee that the browser accepted and actually set the cookie - just a way to make it available immediately in your script.

    0 讨论(0)
提交回复
热议问题