From my understanding $_COOKIE
gives me all the cookies in a user's browser.
But when I do
var_dump($_COOKIE);
I get the following:
Array
(
[wp-settings-1] => m8=o&m2=o&m5=o&m4=o&m3=o&m1=o&m7=o&m0=o
[wp-settings-time-1] => 1329859655
[PHPSESSID] => ST88bLB7PE5S9BbY5oXxLgDIcas
)
This list does not match the list I see in the browser. For example, PHPSESSID is not in the list of cookies in my browser. Am I accessing the wrong variable?
Thanks.
Accessing Cookies with PHP Simplest way is to use either $_COOKIE or $HTTP_COOKIE_VARS variables. Following example will access all the cookies set in above example. You can use isset() function to check if a cookie is set or not.
You can use the print_r or var_dump function to check all available cookies for debugging purposes. print_r( $_COOKIE ); It's that easy to read cookies in PHP!
With PHP, you can both create and retrieve cookie values. The name of the cookie is automatically assigned to a variable of the same name. For example, if a cookie was sent with the name "user", a variable is automatically created called $user, containing the cookie value.
A cookie is a piece of data from a website that is stored within a web browser that the website can retrieve at a later time. Cookies are used to tell the server that users have returned to a particular website.
As mentioned $_COOKIE
only gives you cookies for the current domain/path. You cannot see all cookies in a browser. You can see how this works if you ever sniff/view HTTP packets. When you make an HTTP request, the browser sends cookies to the server. This page has some excellent examples of what that HTTP traffic looks like.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With