I read that in PHP, you can view all the cookies by using print_r, according to http://www.w3schools.com/php/php_cookies.asp .
<?php
print_r($_COOKIE);
?>
But I want to do more with the content of the cookie.
Is there a way to concatenate the cookie names and values into, something like a string variable, without knowing the cookie names, instead of relying on print_r?
I couldn't find answers online. Thank you in advance.
Either of these may work depending on the complexity of your cookie array
implode(',',$_COOKIE)
json_encode($_COOKIE)
serialize($_COOKIE)
I'd advise against this, and just rely on traversing the array
simple example: $_COOKIE['name']
You can get access to all coookie names, without knowing them in advance, with code like this:
foreach ($_COOKIE as $name => $value) {
print "Variable " . $name . " has value " . $value . "<br />\n";
}
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