Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 是";mysqli“u real”u escape“u string”;足以避免SQL注入或其他SQL攻击吗?_Php_Mysql_Security_Sql Injection - Fatal编程技术网

Php 是";mysqli“u real”u escape“u string”;足以避免SQL注入或其他SQL攻击吗?

Php 是";mysqli“u real”u escape“u string”;足以避免SQL注入或其他SQL攻击吗?,php,mysql,security,sql-injection,Php,Mysql,Security,Sql Injection,这是我的代码: $email= mysqli_real_escape_string($db_con,$_POST['email']); $psw= mysqli_real_escape_string($db_con,$_POST['psw']); $query = "INSERT INTO `users` (`email`,`psw`) VALUES ('".$email."','".$psw."')"; 有人能告诉我它是安全的还是容易受到SQL注入攻击或其他SQL攻击 有人能告

这是我的代码:

  $email= mysqli_real_escape_string($db_con,$_POST['email']);
  $psw= mysqli_real_escape_string($db_con,$_POST['psw']);

  $query = "INSERT INTO `users` (`email`,`psw`) VALUES ('".$email."','".$psw."')";
有人能告诉我它是安全的还是容易受到SQL注入攻击或其他SQL攻击

有人能告诉我它是安全的还是容易受到SQL注入攻击或其他SQL攻击

正如uri2x所说,请参见

它们将数据(您的参数)与指令(SQL查询字符串)分开,并且不会留下任何空间让数据污染查询的结构。准备好的陈述解决了其中一个问题

对于无法使用准备好的语句的情况(例如,
限制
),为每个特定目的使用非常严格的白名单是保证安全性的唯一方法

// This is a string literal whitelist
switch ($sortby) {
    case 'column_b':
    case 'col_c':
        // If it literally matches here, it's safe to use
        break;
    default:
        $sortby = 'rowid';
}

// Only numeric characters will pass through this part of the code thanks to type casting
$start = (int) $start;
$howmany = (int) $howmany;
if ($start < 0) {
    $start = 0;
}
if ($howmany < 1) {
    $howmany = 1;
}

// The actual query execution
$stmt = $db->prepare(
    "SELECT * FROM table WHERE col = ? ORDER BY {$sortby} ASC LIMIT {$start}, {$howmany}"
);
$stmt->execute(['value']);
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);

我不知道该怎么做。mysqli_real_escape_string()是一个与mysql_real_escape_string()完全不同的函数。。。也许2015年大多数人都不知道这一点?
$db->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);