Alternatywa dla eregi() i ereg()

Przykład PHP2014-03-07 stopień trudności: łatwy

Niektórzy wiedzÄ… już Å¼e w PHP 5.3.0. odchodzÄ… w niepamięć takie funkcje jak ereg(), eregi()


<?
//funkcja która moze nie być sprawna
function anti_injection($text
)
{
    
$banlist 
= array
        (
        
"insert""select""update""delete""distinct""having""truncate""replace"

       
"handler""like""procedure""limit""order by""group by""asc"
"desc"
        
);
    if ( 
eregi "[a-zA-Z0-9]+"$text 
) )
    {
        
$text trim str_replace $banlist''strtolower $text 
) ) );
    }
    else
    {
        
$text NULL
;
    }
     return(
$text
);
    }


//i po zamianie
function anti_injection($text
)
{
    
$banlist 
= array
        (
        
"insert""select""update""delete""distinct""having""truncate""replace"

       
"handler""like""procedure""limit""order by""group by""asc"
"desc"
        
);
for(
$i=0$i count($banlist); $i
++){
$patern "[".$banlist[$i]."]"
;
if (
preg_match($patern$text
)){
$text trimstr_replace($banlist[$i], ' 'strtolower $text 
) ) );
}
}
return(
$text
);
}
?>

 



 
close
Strona korzysta z plików cookies. Zastosowane pliki cookie służą jedynie do prowadzenia ogólnych statystyk pozwalających na określenie popularności serwisu.