da kommt bestimmt 1 raus oder so.
eval problem
Einklappen
X
-
ich habs nun anders gemacht funzt auch.
verbesserungen bitte anhängen:
PHP-Code:<form name="<?php $_SERVER['PHP_SELF'] ?>" method="post" action="">
<input name="feld1" type="text" value="feld1">
<input name="feld2" type="text" value="feld2">
<input name="feld3" type="text" value="feld3">
<input type="submit" name="submit" value="Senden">
</form>
<?php
/* ******************************************** */
/* */
/* Funktion zum Auswerten von Usereingaben */
/* Author: Mukraker */
/* Version: alpha 0.00000000000001 */
/* */
/* ******************************************** */
//defines
define('TYPE_AUTO', 0);
define('TYPE_GET', 1);
define('TYPE_POST', 2);
define('TYPE_SESSION', 3);
//debug var function
function vd($var)
{
//$var auf array checken
if( is_array($var) OR is_object($var)) {
echo "<hr><pre style=\"background-color:#FF8888\">";
print_r($var);
echo "</pre><hr>";
} elseif(is_string($var)) {
echo "<hr><p style=\"background-color:#FF8888\">".$var."<p><hr>";
} else {
echo "<hr><p style=\"background-color:#FF8888\">Inhalt der var:<br>".$var."<p><hr>";
}
}
//check_fields function
function check_fileds($array) {
foreach($array as $key => $value) {
$var = false;
//check typ
switch( $value['type'] )
{
case TYPE_SESSION:
if( isset($_SESSION[$value['name']]) )
$var = $_SESSION[$value['name']];
break;
case TYPE_POST:
if( isset($_POST[$value['name']]) )
$var = $_POST[$value['name']];
break;
case TYPE_GET:
if( isset($_GET[$value['name']]) )
$var = $_GET[$value['name']];
break;
case TYPE_AUTO:
if( isset($_REQUEST[$value['name']]) )
$var = $_REQUEST[$value['name']];
break;
}
//extra if
if(isset($value['extra'])) {
$extra = substr($value['extra'], 1, -1);
$input = $var;
}
//check if the var exist
if(!$var) {
$novar[] = array($value['name'],$value['msg']);
}elseif(isset($value['extra'])) {
$extra = substr($value['extra'], 1, -1);
$input = $var;
$evalstr = "if(".$extra.") {
if(isset(\$value['extra2'])) {
\$extra2 = \$value['extra2'];
} else {
\$extra2 = \$value['msg'];
}
\$novar[] = array(\$value['name'],\$extra2);
}";
eval($evalstr);
/* dass muss man unbeding mal anders lösen
if(eval($extra)) {
if(isset($value['extra2'])) {
$extra2 = $value['extra2'];
} else {
$extra2 = $value['msg'];
}
$novar[] = array($value['name'],$extra2);
}*/
}
}
//build array
if(isset($novar)) {
foreach ($novar as $key => $value) {
// hier könnte man evtl noch was machen
}
}
return $novar;
}
if(isset($_POST['submit'])){
//check array
$array = array();
$array[] = array('name' => 'feld1',
'msg' => 'hey feld1 eingeben',
'typ' => TYPE_POST,
'extra' => '($input != 3)',
'extra2' => 'hey extra bed nicht erfüllt');
$array[] = array('name' => 'feld2',
'msg' => 'hey feld2 eingeben',
'typ' => TYPE_POST,
'extra' => '($input != 2)',
'extra2' => 'hey extra bed nicht erfüllt');
$array[] = array('name' => 'feld3',
'msg' => 'hey feld3 eingeben',
'typ' => TYPE_POST);
$array[] = array('name' => 'feld4',
'msg' => 'hey feld4 eingeben',
'typ' => TYPE_POST);
vd(check_fileds($array));
}
//show_source(__FILE__);
?>thx Mukraker
Kommentar
Kommentar