0

Is there a way of retrieving the names of the cookies that are set in PHP?

In my website, I have many cookies that start with "answered" proceeded by a number; like $_COOKIE["answered66"]. The values are integers from 1 to 5.

I could write a for loop to go through every number, but I was wondering if there were any more efficient way of doing this. If I could some how retrieve like a list of names of set cookies as a array, I could go from there.

dshukertjr
  • 15,244
  • 11
  • 57
  • 94
  • 5
    Possible duplicate of [Can I display all the cookies I set in PHP?](http://stackoverflow.com/questions/9577029/can-i-display-all-the-cookies-i-set-in-php) – Christian Nov 11 '15 at 04:01
  • Well, I looked at that question, but I can't think of a way of programming php to find all the cookie name and finding those that start with "answered" – dshukertjr Nov 11 '15 at 04:04
  • You said you wanted a list and you'd go from there. That answer gives you the list, so you can go from there! If you don't know how to go from there then you might want to re-word your question. Still, the answer is quite trivial, I'm confident you can solve this yourself. https://stackoverflow.com/questions/4366730/check-if-string-contains-specific-words – Christian Nov 11 '15 at 04:08

3 Answers3

0

$_COOKIE is just a standard PHP associative array, so you can view it like any other, e.g.:

var_dump($_COOKIE);

More info is available on php's $_COOKIE page.

Maltronic
  • 1,782
  • 10
  • 21
0

Use Print_r

Print_r($_COOKIE);

Or

<pre>
<?php print_r( $_COOKIE ); ?>
</pre>
Abhishek Sharma
  • 6,689
  • 1
  • 14
  • 20
0
foreach ($_COOKIE as $key=>$val) {
    echo $key.' is '.$val."<br>";
}
N3R4ZZuRR0
  • 2,400
  • 4
  • 18
  • 32