السلام عليكم ورحمة الله وبركاته
كيف تحمي السكربتات من الثغرات !!
اليكم بهذا الشرح المبسط :
دالة لتأمين المدخلات :
ثم تم الغاء مفعول اكواد html بالدالة htmlspecialchars
ثم ازالة المسافات من اول وآخر النص بالدالة trim
ولاتحتاج لزيادة وعلى حتى دالة الاستبدال لأنك تلقائيا ألغيت مفعول اكواد الـ html . دالة لتأمين المخرجات :
هكذا :
OR
كيف تحمي السكربتات من الثغرات !!
اليكم بهذا الشرح المبسط :
دالة لتأمين المدخلات :
function save($vars){
$vars = addslashes($vars);
$vars = htmlspecialchars($vars);
$vars = trim($vars);
return $vars;
}
لأن تم تأمين النص أولا من رموز ' " ; / بالداله addslashes$vars = addslashes($vars);
$vars = htmlspecialchars($vars);
$vars = trim($vars);
return $vars;
}
ثم تم الغاء مفعول اكواد html بالدالة htmlspecialchars
ثم ازالة المسافات من اول وآخر النص بالدالة trim
ولاتحتاج لزيادة وعلى حتى دالة الاستبدال لأنك تلقائيا ألغيت مفعول اكواد الـ html . دالة لتأمين المخرجات :
function save2($vars){
$vars = stripslashes($vars);
$vars = htmlspecialchars($vars);
return $vars;
}
وبالنسبه لإستقبال البيانات من خلال الرابط اذا كانت ارقام فما فعلت انت كافي والله اعلم وهي بتمرير المتغير للداله intval$vars = stripslashes($vars);
$vars = htmlspecialchars($vars);
return $vars;
}
هكذا :
$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;
}
والاستخدام هكذا :{
$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]);
هذا ما لدي والله اعلم