Home > Backend Development > PHP Tutorial > 过滤get交付过来的变量htmlspecialchars就够了吧

过滤get交付过来的变量htmlspecialchars就够了吧

WBOY
Release: 2016-06-13 13:16:11
Original
915 people have browsed it

过滤get提交过来的变量htmlspecialchars就够了吧?
比如要实现搜索用户名的功能,其实用户名是get过来的,用htmlspecialchars就够安全了吧?

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->htmlspecialchars(trim($_GET['username']), ENT_QUOTES);
Copy after login


------解决方案--------------------
addslashes 处理(')、(")、(\)与 NULL
------解决方案--------------------
其实你是要防sql注入吧。对于
因此,最安全的还是通过 mysql_real_escape_string() 来转义防止攻击数据库, 可以下面这样写就安全了:

if (get_magic_quotes_gpc()) {
$username= stripslashes($_GET['username']);
}
else {
$username= $_GET['username'];
}

$username= mysql_real_escape_string($username);
...................................
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template