2 Hàm Code Chống Làm Cho Website Dính Lỗi SQL Injection

Đánh Giá Bài Vi?t





Hàm chống SQL Injection Loại 1 :


function anti_sql($sql) {    $sql = preg_replace(sql_regcase("/(from|select|insert|delete|where|drop table|show tables|#|*|--|\)/"),"",$sql);    return trim(strip_tags(addslashes($sql))); #strtolower()}

Chống sql inject Loại 2

các bạn có thể lựa chọn phương pháp khác nhau và function cho phù hợp
Code:


function id_replace($id)
    {
        $id = str_replace("+","",$id);
        $id = str_replace("'","''",$id);
        $id = str_replace("UNI0N","",$id);
        $id = str_replace("select","",$id);
        $id = str_replace("*","",$id);
        $id = str_replace("%","",$id);
        $id = str_replace("%","",$id);
        $id = str_replace("2b","",$id);
        if (strlen($id) > 10)
        {
            $id="";
        }
    return $id;
    }
    
    function string_replace($string)
    {
        $string = str_replace(""",""",$string);
        $string = str_replace("+","",$string);
        $string = str_replace("'","''",$string);
        $string = str_replace("<","[",$string);
        $string = str_replace(">","]",$string);
        $string = str_replace("&gt;","]",$string);
        $string = str_replace("&lt;","[",$string);
        $string = str_replace("UNI0N","",$string);
        $string = str_replace("select","",$string);
        $string = str_replace("*","",$string);
        $string = str_replace("%","",$string);
        $string = str_replace("%","",$string);
        $string = str_replace("2b","",$string);
        if (strlen($string) > 15)
        {
            $string="";
        }
    return $string;
    }


2 Hàm Code Chống Làm Cho Website Dính Lỗi SQL Injection Reviewed by blogspotger on 7/04/2016 Rating: 5

No comments:

Cảm Ơn Bạn Đã Nhận Xét Và Góp Ý !!!

All Rights Reserved by Quỳnh Phương Blog © 2016-2017
Thiết Kế Bìa NTQP52

Biêu Mẫu Liên Hệ

Name

Email *

Message *

Powered by Blogger.
Chat
1