繁体   English   中英

mysql is_numeric sql注入

[英]mysql is_numeric sql injection

我的网页上有一个分页。 因此,如果我有来自分页的帖子,我想在查询中添加一行:

$q="";
if(isset($_POST["inpi"])){
    $in = $_POST["inpi"];
    if(is_numeric($in)){
        $q = "and c.id < '$in'"; // add this to mysql
    }
    else{die("something is wrong!");}
}

所以我不能在这里使用准备陈述。

select k.user, c.id, c.from, c.sent, c.message, c.recd from chat c
inner join cadastro k on c.from=k.id
where `from`=? and `to`=? $q

注意$ q变量,如果post为空或and c.id <'$ in',它将没有任何值。

它足够安全吗?

您可以随时累积参数并按如下方式构建参数:

$query = "SELECT ... WHERE `from`=? AND `to`=?";
$binds = array("ss", &$from, &$to);

if (isset($_POST["inpi"])) {
  $query .= " AND c.id < ?";

  $$binds[0] .= "i";
  $binds[] = &$_POST["inpi"];
}

$stmt = $mysqli->prepare($query);

call_user_func_array(array($stmt, 'bind_param'), $binds);

我尚未对此进行测试,但是它基于此代码 ,可能需要进行一些调整才能起作用。

PDO的execute()函数直接获取一个array ,使用起来更容易。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM