防止从$ _GET方法显示HTML
我目前正在开发用户管理系统。 我在其他网站中有注册和登录页面,它们都使用 $_GET 函数。经过一番尝试后,我注意到,当您确切知道自己在做什么时,可以从 GET 参数打印 HTML 代码。可能有一种方法可以通过在 img 标签中使用 onerror 来利用这个问题,例如
如何防止这种情况发生?
网址:users.php?s=login&mail=">%20
它显示的内容: 我的代码:
print ' <form action="' .$url. '" method="post">
<input type="hidden" name="a" value="login"/>
<b><label for="mail">E-Mail:</label></b>
<input type="email" id="mail" name="mail" maxlength="50" value="' .$mail. '" required><br><br>
如何防止这种情况发生?
I'm currently working on a user management system.
I have the register and sign-in page among other sites, that all use the $_GET function. After experimenting around a bit I noticed that you can print HTML code from the GET parameters when you exactly know what you are doing. There is probably a way to exploit this by using the onerror in an img tag e.g.
How can I prevent this from happening?
The URL: users.php?s=login&mail=">%20<img%20src=%27../images/notification_bell.png%27%20width=%2725px%27>
What it displays:
And my code:
print ' <form action="' .$url. '" method="post">
<input type="hidden" name="a" value="login"/>
<b><label for="mail">E-Mail:</label></b>
<input type="email" id="mail" name="mail" maxlength="50" value="' .$mail. '" required><br><br>
How can I prevent this from happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
HTMLSpecialChars
将用户定义的字符转换为Web-Safe代码。 https://www.php.net/htmlspecialchars也许您也可以使用
fill_var
/代码>验证电子邮件,如果它无效,请删除它。 https://www.php.net/filter_var
use
htmlspecialchars
to convert user-defined characters into web-safe code. https://www.php.net/htmlspecialcharsalso, maybe you could use
filter_var
to validate the email and simply unset it if it's invalid. https://www.php.net/filter_var