您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

PHP代码避免sql注入

PHP代码避免sql注入

更好的方法

您可以使用下面的功能,但我/我们建议您不要使用该功能,因为MysqL_* 现在该功能已由社区维护和更新。

仅出于您的知识

 $id = MysqL_prep($_POST['id']);


function MysqL_prep($value)
{
    $magic_quotes_active = get_magic_quotes_gpc();
    $new_enough_PHP = function_exists("MysqL_real_escape_string"); // i.e. PHP >= v4.3.0
    if ($new_enough_PHP) { // PHP v4.3.0 or higher
        // undo any magic quote effects so MysqL_real_escape_string can do the work
        if ($magic_quotes_active) {
            $value = stripslashes($value);
        }
        $value = MysqL_real_escape_string($value);
    } else { // before PHP v4.3.0
        // if magic quotes aren't already on then add slashes manually
        if (!$magic_quotes_active) {
            $value = addslashes($value);
        }
        // if magic quotes are active, then the slashes already exist
    }
    return  $value ;
}

防止PHP中进行SQL注入的最佳方法?

php 2022/1/1 18:50:32 有302人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶