Why isn't this simple PHP Forloop working?
Posted
by
Jake
on Stack Overflow
See other posts from Stack Overflow
or by Jake
Published on 2011-01-15T22:39:29Z
Indexed on
2011/01/15
22:53 UTC
Read the original article
Hit count: 303
php
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?
© Stack Overflow or respective owner