php - 在人们将访问的页面上运行此查询是否安全?

标签 php security mysqli prepared-statement

抱歉,这可能是一个非常愚蠢的问题,但是在人们将要查看的页面上运行此代码是否安全,或者我应该将其包装到函数中并调用它?

$stmt = $db->prep_stmt("select * from .... where userid = ? and username = ?"); 

/* Binding 2 parameters. */
$stmt->bind_param("is", $userid, $username);

/* Binding 2 result. */
$stmt->bind_result($isbn, $title, $author, $coef, $bookid);

/* Executing the statement */
$stmt->execute( ) or die ("Could not execute statement");

/*
 * Making PHP buffer the whole result,
 * not recommended if there is a blob or
 * text field as PHP eats loads of memory
 */
$stmt->store_result();
while ($stmt->fetch()) {
 /*
  * Here you can use the variables $isbn, $title, $author, $coef, $bookid,
  * which contatin the data for 1 row.
  */
  print "<tr>".
  "<td>".$isbn."</td>".
  "<td>".$title."</td>".
  "<td>".$author."</td>".
  "</tr><tr><td>";

}

最佳答案

从安全角度来看,它们是相同的。这是软件设计的问题。但是,您可能需要考虑更好的错误处理(至少对于生产而言)。具体来说,实际上没有必要泄漏错误的原因(“无法执行语句”)。通常,您需要一个通用错误页面(“抱歉,服务器有问题!尝试转到主页。”)。

关于php - 在人们将访问的页面上运行此查询是否安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4467635/

相关文章:

php - 警告 : mysql_query() expects parameter 2 to be resource

php - 用图片更新Mysql内容

php - 加泰罗尼亚语字符 à 和 è 不适用于 php imagestringup - 如何解码它们?

php - Firebug AJAX 请求中止 - 无响应正文或 header (同一域)

java - 签署证书的解决方案

php - 将ID从表单携带到后端脚本,并将其值保存在数据库中

php - 使用已使用 filter_input() 过滤的 htmlspecialchars() 从数据库输出数据

php ON DUPLICATE UPDATE 不起作用

php - 什么时候 PHP 代码真的应该被视为不安全的?

laravel - centos Server中laravel的正确权限是什么?