$_COOKIE
The $_COOKIE superglobal contains data stored in cookies sent by the browser to the server. Cookies are small key-value pairs that persist across requests and are commonly used to remember user preferences, login states, or tracking information.
Cookies are created on the server using setcookie() and are then automatically included by the browser in future requests to the same domain. Once set, cookies can be accessed in PHP through the $_COOKIE array.
Because cookies come from the client (the browser), their values should never be fully trusted. Always check if a cookie exists before accessing it, and treat its contents as user-controlled data.
In WordPress and plugins like MemberPress, cookies are often used behind the scenes for authentication and session handling. Developers usually read cookies rather than manually creating complex cookie systems.
Key points:
- Cookies persist between requests
- They are automatically sent by the browser
- Always check for existence before using
- Commonly used for preferences and login state