这段 PHP 代码是否会打开一个 SQL 注入网站
我正在开发一个网络应用程序,我遇到了这个代码片段,
$email=$_POST['email'];
$pass=$_POST['pass'];
$pass=md5($pass);
$query=mysql_real_escape_string($email,$link);
//echo $query."<br>";
$sql=mysql_query("SELECT pass FROM users WHERE email='".$email."'",$link);
if($row=mysql_fetch_array($sql))
{
我认为程序员的意图是 $query=mysql_real_escape_string($email,$link);
为 $email=mysql_real_escape_string($ email,$link);
我的想法正确吗?
I'm working on a web app and I came across this code snippit
$email=$_POST['email'];
$pass=$_POST['pass'];
$pass=md5($pass);
$query=mysql_real_escape_string($email,$link);
//echo $query."<br>";
$sql=mysql_query("SELECT pass FROM users WHERE email='".$email."'",$link);
if($row=mysql_fetch_array($sql))
{
I think the programmer intended $query=mysql_real_escape_string($email,$link);
to be $email=mysql_real_escape_string($email,$link);
Do I have the right idea here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,你完全正确 - 只需更正该部分,就像你所说的那样,将其更改为
,这样就可以防止 SQL 注入。
顺便说一句,我建议您使用
hash("sha512", xxx)
而不是md5
,因为 MD5 即将过时。如果您的列大小不允许这样做并且您无法更改它,那仍然可以。Yes, you're absolutely right - just correct that part, like you said, by changing it to
, and that will protect against SQL injection there.
On a side note, I suggest you use
hash("sha512", xxx)
instead ofmd5
because MD5 is becoming obsolete. If your column size doesn't allow for that though and you don't have the ability to change it, it's still OK.是的,
$email
已设置,但随后未进行过滤,它直接在查询中使用。正如您所指出的,它看起来像是一个错误,因为查询中未使用过滤后的值。Yes,
$email
is set, but then not filtered, it's used directly in the query. As you pointed out, it looks like an error as the filtered value is not being used in the query.为了防止盲目 SQL,请使用两个过滤器包装您的 POST 数据:
to prevent from blind SQL , wrap your POST data with tow more filters: