Home  >  Article  >  php教程  >  php addslashes sql防注入函数

php addslashes sql防注入函数

WBOY
WBOYOriginal
2016-06-13 11:18:181044browse

addslashes可会自动给单引号,双引号增加\这哦,这样我们就可以安全的把数据存入数据库中而不黑客利用。*///参数'A..z'界定所有大小写字母均被转义echo addcslashes('foo[ ]','A..z'); //输出:foo[ ]  

addslashes可会自动给单引号,双引号增加这哦,这样我们就可以安全的把数据存入数据库教程中而不黑客利用。
*/
//参数'a..z'界定所有大小写字母均被转义
echo addcslashes('foo[ ]','a..z');       //输出:foo[ ]

//
$str="is your name o'reilly?";      //定义字符串,其中包括需要转义的字符
echo addslashes($str);       //输出经过转义的字符串

/*
定义和用法
addslashes() 函数在指定的预定义字符前添加反斜杠。

这些预定义字符是:

单引号 (')
双引号 (")
反斜杠 ()
null
语法
addslashes(string)
*/

//当然这个函数更安全

$str="test";        //定义包含特殊字符的字符串
$new=htmlspecialchars($str,ent_quotes);     //进行转换操作
echo $new;           //输出转换结果
//不过输出时要用到

$str="jane & 'tarzan'";      //定义html字符串
echo html_entity_decode($str);        //输出转换后的内容
echo "
";
echo html_entity_decode($str,ent_quotes);     //有可选参数输出的内容


Statement:
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