Cześć,
Zrobiłem sobie skrypt oczyszczajacy tablice z niechcianych kodów np. javascript html itp. i mam taki problem, że powinien mi w wypadku gdy usunie z ciągu typ danych zakazanych to powinien wyskoczyć komunikat jaki to typ itp. czyści natomiast bardzo skutecznie. Oto kod:
<?php
$security['java'] = 0;
$security['html'] = 0;
$security['style'] = 0;
$security['cdata'] = 0;
$security['mysql'] = 0;
function CleanScript($tekst,$jv=TRUE,$htm=TRUE,$css=TRUE,$cd=TRUE,$mysql=TRUE){
$java = array('@<script[^>]*?>.*?</script>@si'); // javascript $html = array('@<[\/\!]*?[^<>]*?>@si'); // html $style = array('@<style[^>]*?>.*?</style>@siU'); // css $cdata = array('@<![\s\S]*?--[ \t\n\r]*>@'); // CDATA $txt = $tekst;
$e = $tekst;
if ($htm == 1
){$tekst = preg_replace($html, '', $tekst); $security['html'] = strcmp($e,$tekst);}; $q = $tekst;
if ($jv == 1
){$tekst = preg_replace($java, '', $tekst); $security['java'] = strcmp($q,$tekst);}; $w = $tekst;
if ($css == 1
){$tekst = preg_replace($style, '', $tekst); $security['style'] = strcmp($w,$tekst);}; $r = $tekst;
if ($cd == 1
){$tekst = preg_replace($cdata, '', $tekst); $security['cdata'] = strcmp($r,$tekst);}; $t = $tekst;
$txt = $tekst;
return $txt;
}
foreach($_GET as $klucz => $wartosc)
{
$z = 'UnSec';
foreach($a as $value){
{
$_GET[$klucz] = CleanScript($_GET[$klucz],FALSE,FALSE,FALSE,FALSE);
} else
{
}
}
}
foreach($_POST as $klucz => $wartosc)
{
$z = 'UnSec';
foreach($a as $value){
{
$_POST[$klucz] = CleanScript($_POST[$klucz],FALSE,FALSE,FALSE,FALSE);
} else
{
}
}
}
foreach($security as $klucz => $wartosc)
{
if ($wartosc == 1)
echo '<h1>Zmienna zawiera niedozwolone treści: security error type:'.$klucz.'</h1>'; }
?>
Ten post edytował patryk9200 13.11.2009, 23:38:24