首页 > php开发 > php 防止sql注入代码

php 防止sql注入代码

<?php
function inject_check($sql_str) { //防止注入
    $check = eregi('select|insert|update|delete|\'|/*|*|../|./|union|into|load_file|outfile', $sql_str);
    if ($check) {
        echo "输入非法注入内容!";
        exit();
    } else {
        return $sql_str;
    }
}
function checkurl() { //检查来路
    if (preg_replace("/https?://([^:/]+).*/i", "1", $_server['http_referer']) !== preg_replace("/([^:]+).*/", "1", $_server['http_host'])) {
        header("location: http://www.phprm.com");
        exit();
    }
}
//调用
checkurl();
$str = $_get['url'];
inject_check($sql_str); //这条可以在获取参数时执行操作


文章网址:http://www.phprm.com/develop/fs4721.html

随意转载^^但请附上教程地址。

标签:php 防止sql 注入代码

相关文章

发表留言