我注意到一些奇怪的mysql_real_escape_string功能.它没有逃脱,“或者”例如:“TEST”没有被转换成\“TEST\”.
功能正常"(仔细观察,你看它们是不同的)
任何想法如何解决这个问题,我宁愿不从头开始编写这个函数.是否已弃用,是否有替代方案?
编辑:谢谢大家的回答.为了澄清我试图将这个字符串我喜欢的东西"目录\ r \n"插入到数据库中,并且由于某种原因它无法正常工作.一切都适用于任何其他字符串,我没有得到任何错误消息,它只是没有出现在数据库中.所以我认为这可能与".
对我这么容易!
EDIT2
$interestTable = "5431591 1 Things I Like” <br>";
//problem lies here
$count = 0;
$interestTable = preg_replace_callback( '/<br>/', function( $match) use( $tagName, &$count) {
return $tagName[$count++][0] . ' ' . PHP_EOL;
}, $interestTable);
//$interestTable = "5431591 1 Things I Like” catalog \r\n" after format
$interestTable = mysql_real_escape_string($interestTable);
echo $interestTable;
mysql_query("INSERT INTO $tbl_name(userID,storyID,rank, storyType, interestTable)VALUES('$userID','$storyID','$rank','$storyType','$interestTable')", $dbh1);
Run Code Online (Sandbox Code Playgroud)
EDIT3我没有弄错,我把字符串从我喜欢的东西"目录\ r \n"更改为物品我AA目录\ r \n并且它有效.我不知道为什么会发生这种情况,也许在转换为字符串后,某些东西会被编码弄乱,但我不确定.我所知道的肯定,取消后"从字符串,一切工作正常
对.永远不要依赖这样的黑名单机制来保障安全.它坏了,可以导致一些有趣的SQL注入:
$query = "SELECT id, title, body FROM posts WHERE id = " . mysql_real_escape_string($_GET['id']);
Run Code Online (Sandbox Code Playgroud)
这仍然可以注入:
1 OR 1=1
Run Code Online (Sandbox Code Playgroud)
导致:
SELECT id, title, body FROM posts WHERE id = 1 OR 1=1
Run Code Online (Sandbox Code Playgroud)
返回所有结果.不相信这是坏事吗?好...
1 OR 1=1 UNION SELECT id, username, password FROM users
Run Code Online (Sandbox Code Playgroud)
哎呦!
为什么这是注射剂?开发人员忘了引用数字ID.如果你能永远看到自己犯这个错误,你应该寻求一个更好的解决方案.
我的建议?停止使用字符串连接,停止使用已弃用的mysql_函数,并使用参数化查询转移到MySQLi或PDO,其中内容与查询语言明确分开.