如果插入用户输入而不修改SQL查询,则应用程序容易受到SQL注入的攻击,如下例所示:
$unsafe_variable = $_POST['user_input'];
mysql_query("INSERT INTO `table` (`column`) VALUES ('$unsafe_variable')");
Run Code Online (Sandbox Code Playgroud)
这是因为用户可以输入类似的内容value'); DROP TABLE table;--,查询变为:
INSERT INTO `table` (`column`) VALUES('value'); DROP TABLE table;--')
Run Code Online (Sandbox Code Playgroud)
可以采取哪些措施来防止这种情况发生?
我正在运行PHP脚本,并继续收到如下错误:
注意:未定义的变量:第10行的C:\ wamp\www\mypath\index.php中的my_variable_name
注意:第11行的未定义索引:my_index C:\ wamp\www\mypath\index.php
第10行和第11行看起来像这样:
echo "My variable value is: " . $my_variable_name;
echo "My index value is: " . $my_array["my_index"];
Run Code Online (Sandbox Code Playgroud)
这些错误消息的含义是什么?
他们为什么突然出现?我曾经使用这个脚本多年,我从来没有遇到任何问题.
我该如何解决?
这是一个一般参考问题,供人们链接到重复,而不是一遍又一遍地解释这个问题.我觉得这是必要的,因为关于这个问题的大多数现实世界的答案都非常具体.
相关元讨论: