Re: can I do a for each here??

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



AndreaD wrote:
I have about 10 text boxes each taking in value (ages), The code I have
checks for a value and if it is set it then sets the cookie to that value.
The else just clears the value. On the next page I use a foreach to get the
values but I think there must be a quicker way to collect the data appart
from 10 if-else staements.

if (isset($andrea){

setcookie("cookie[andrea]", "$andrea");
}

else {setcookie("cookie[$andrea]", "");

}

Let's look at your two setcookie() calls:

setcookie("cookie[andrea]", "$andrea")
setcookie("cookie[$andrea]", "")

Just for debugging purposes, assume $andrea is initialized prior to this as follows:

$andrea = 29;

So, your code says that you want a cookie with the following name and value (available on the next request):

$_COOKIE['cookie[andrea]'] = 29;

Is that really what you want?

Of course, it's very odd that if $andrea is not set, you want a cookie like this:

$_COOKIE['cookie[]'] = '';

In addition, you will be generating a notice, because you're using $andrea in the name of the cookie, although you're first making certain that $andrea isn't set.

I'm also a bit concerned about where $andrea originates. Is this coming from the user, and you're trusting it? That's a very dangerous practice.

If you explain your problem, we might be able to offer some help.

Chris

--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux