السلام عليكم ورحمة الله وبركاته
كيف تحمي السكربتات من الثغرات !!
اليكم بهذا الشرح المبسط :
دالة لتأمين المدخلات :
كود
<?
function save($vars){
$vars = addslashes($vars);
$vars = htmlspecialchars($vars);
$vars = trim($vars);
return $vars;
}
?>
لأن تم تأمين النص أولا من رموز ' " ; / بالداله addslashes
ثم تم الغاء مفعول اكواد html بالدالة htmlspecialchars
ثم ازالة المسافات من اول وآخر النص بالدالة trim
ولاتحتاج لزيادة وعلى حتى دالة الاستبدال لأنك تلقائيا ألغيت مفعول اكواد الـ html .
دالة لتأمين المخرجات :
كود
<?
function save2($vars){
$vars = stripslashes($vars);
$vars = htmlspecialchars($vars);
return $vars;
}
?>
وبالنسبه لإستقبال البيانات من خلال الرابط اذا كانت ارقام فما فعلت انت كافي والله اعلم وهي بتمرير المتغير للداله intval
هكذا :
كود
<?
$id = intval($_GET["id"]);
?>
وأما اذا كانت البيانات نصوص فإليك الداله للتأمين من حقن قواعد البيانات :
كود
<?
function clean_value($getandpost)
{
$getandpost = htmlspecialchars($getandpost);
$getandpost = str_replace("select","",$getandpost);
$getandpost = str_replace("update","",$getandpost);
$getandpost = str_replace("insert","",$getandpost);
$getandpost = str_replace("where","",$getandpost);
$getandpost = str_replace("like","",$getandpost);
$getandpost = str_replace("or","",$getandpost);
$getandpost = str_replace("and","",$getandpost);
$getandpost = str_replace("set","",$getandpost);
$getandpost = str_replace("into","",$getandpost);
$codenumber = str_replace("'", "", $codenumber);
$codenumber = str_replace(";", "", $codenumber);
$codenumber = str_replace(">", "", $codenumber);
$codenumber = str_replace("<", "", $codenumber);
$getandpost=strip_tags($getandpost);
return $getandpost;
}
?>
والاستخدام هكذا :
كود
<?
clean_value($_POST[TEXT]);
?>
OR
كود
<?
clean_value($_GET[TEXT]);
?>
هذا ما لدي والله اعلم