How to Get a Cookie in PHP?

Find out how to access a cookie in PHP

You can get the value of a cookie by its name via the $_COOKIE superglobal array, like so:


Using the $_COOKIE array you can access all cookies (by their name) that are passed to the current PHP script via HTTP cookies. For example, if you have a cookie called "foo", you can access it like so:


Please note that if you have dots (.) or spaces ( ) in the cookie name, then they will be replaced with underscores (_).

Since $_COOKIE is a superglobal, it is available in all scopes throughout your script.

Hope you found this post useful. It was published . Please show your love and support by sharing this post.