Why isn't this simple PHP Forloop working?
- by Jake
First here's the code:
<?php
$qty = $_GET['qty'];
for($i=0; $i < $qty; $i++)
{
setcookie('animals', $_COOKIE['animals'].'(lion)', time()+3600);
}
?>
Here's what I'm trying to do:
I want to set the value of the "animals" cookie to "(lion)". The number of instances of "(lion)" that should be in the cookie is determined by the "qty" GET parameter's value. So for example if the pages url is:
http://site.com/script.php?qty=10
then the value of the cookie should be:
(lion)(lion)(lion)(lion)(lion)(lion)(lion)(lion)(lion)(lion)
but now it just sets the value once despite the setcookie function being inside the loop, why isn't it working?