如果插入用户输入而不修改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)
可以采取哪些措施来防止这种情况发生?
为什么一个人不应该使用mysql_*功能的技术原因是什么?(例如mysql_query(),mysql_connect()或mysql_real_escape_string())?
即使他们在我的网站上工作,为什么还要使用其他东西?
如果他们不在我的网站上工作,为什么我会收到错误
警告:mysql_connect():没有这样的文件或目录
我在Ubuntu 14.04上安装了PHP 7,MySQL 5.5.47.我已经检查了已安装的扩展程序
sudo apt-cache search php7-*
Run Code Online (Sandbox Code Playgroud)
它输出我:
php7.0-common - Common files for packages built from the PHP source
libapache2-mod-php7.0 - server-side, HTML-embedded scripting language (Apache 2 module)
php7.0-cgi - server-side, HTML-embedded scripting language (CGI binary)
php7.0-cli - command-line interpreter for the PHP scripting language
php7.0-phpdbg - server-side, HTML-embedded scripting language (PHPDBG binary)
php7.0-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary)
libphp7.0-embed - HTML-embedded scripting language (Embedded SAPI library)
php7.0-dev - Files for PHP7.0 module development
php7.0-dbg - Debug …Run Code Online (Sandbox Code Playgroud)