Forum Moderators: coopster

Message Too Old, No Replies

An elegant way of writing 'or' for many variables?

         

kiwibrit

11:09 pm on Jun 9, 2007 (gmt 0)

10+ Year Member



When checking for email injection, I successfully use code something like the following:


$question = $validateform->injection($Name) ¦¦ $validateform->injection($Organization)
¦¦ $validateform->injection($Address_1) ¦¦ $validateform->injection($Address_2) ¦¦ $validateform->injection($Town)
¦¦ $validateform->injection($Post_code);

Problem is I am at present writing a form with a whole bunch of inputs - so the above sequence is going to look a bit massive writing it that way. I guess it will still work OK - but is there a more elegant way of writing the code?

eelixduppy

2:14 am on Jun 10, 2007 (gmt 0)



You could maybe do something like this:

foreach($_POST as $input) {
if(!$validateform->injection($input)) { #this depends on what the function returns if there is an injection found
echo 'Injection detected';
exit;
}}

This code, however, assumes that all post variables will be checked with this function. If you want to do it another way, you can use a similar technique, you just have to be more specific.

Habtom

6:41 am on Jun 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The reply looks quite elegant to me.

Hab

[edited by: Habtom at 6:41 am (utc) on June 10, 2007]

kiwibrit

8:12 am on Jun 10, 2007 (gmt 0)

10+ Year Member



eelixduppy, neat. Thank you.

As far as the form variables go, your reply begs another question, which I had been thinking about since I posted my question. I'll do a bit more delving, and start a separate thread f I need to follow up.