Jump to content

eval() challenge


manohoo

Recommended Posts

A foreach statement produces 3 strings per iteration:

 

foreach($_POST as $key=>$value) { 
$str1 = "$"."val_"."$key = new validation ('$key', '$value', '$val[$key]', null);";
$str2 = "$"."val_"."$key"."->validate()";
$str3 = "$"."rs .= "."$"."val_"."$key"."->error;";
echo "$str1 <br />";
echo "$str2 <br />";
echo "$str3 <br />";	
}

Each iteration produces output as follows:

$val_master_ARSAcctNo = new validation ('master_ARSAcctNo', 'PM25-00001', 'arsacctno_pmi', null);
$val_master_ARSAcctNo->validate()
$rs .= $val_master_ARSAcctNo->error; 

I want to execute each one of the strings using eval(), so far I've been unsuccessful, any ideas?

 

 

Link to comment
https://forums.phpfreaks.com/topic/243200-eval-challenge/
Share on other sites

Just use an array -

foreach($_POST as $key=>$value) { 
$val[$key] = new validation ($key, $value, $val[$key], null);
$val[$key]->validate();
$rs .= $val[$key]->error; 
}

 

Also, by using eval, you will need to validate all the post keys and values you put into it to prevent php code injection into your script.

Link to comment
https://forums.phpfreaks.com/topic/243200-eval-challenge/#findComment-1249080
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.