Is there a more elegant way of doing this? |
||
![]() CinC snarkles I'm re-working SNEAK atm (damn you, CyberTNT! ;)) and this is something that's always bugged me. There's a HUGE chunk of code that's like: switch ($_POST['crypt_method']) {
case 'asc2bin':
$text = asc2bin($text);
break;
case 'asc2hex':
$text = asc2hex($text);
break;
case 'bin2asc':
$text = bin2asc($text);
break;
case 'hex2asc':
$text = hex2asc($text);
break;
case 'binary2hex':
$text = binary2hex($text);
break;
case 'hex2binary':
$text = hex2binary($text);
break;
...
...and so on. Basically,
"Call the function named whatever they selected from the drop-down" I can't figure out a better way to do it though, apart from like: // Validate that the crypt method is within a list of allowed values
$crypt_method = $_POST['crypt_method'];
$allowed_methods = array('asc2bin', 'bin2asc' .... );
if (!in_array($crypt_method, $allowed_method)) {
die("Don't try to h4x0r me, dinglefritz!");
}
// Call the function using ... *gasp!* ... eval()
eval($crypt_method());
...which seems kind of hackerish at best.
Any other thoughts? Replies:
|
||
| CyberArmy::Forum v0.6 Generated In 0.02246 seconds |