如何避免用户在我的表单中输入 php 代码
如何阻止用户在我的表单中输入 。
我正在使用 urlencode(),然后在将数据回显到我的页面时使用 urldecode(),最好的做法是什么?
更新:
写入数据库
htmlentities (urlencode($_POST['postmessage']));
我正在使用文本 urlencoded: I am using:
<?php echo htmlentities (urldecode($row['content'])) ?>
以回显保存的数据。这样就够了吗??
How can I stop users entering <?php ?>
into my forms.
I am using urlencode() and then using urldecode() when echoing data onto my page what is the best thing to do??
UPDATE:
I am writing to the database with the text urlencoded:
htmlentities (urlencode($_POST['postmessage']));
I am using:
<?php echo htmlentities (urldecode($row['content'])) ?>
to echo the saved data. Is that enough??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我建议您使用 HTML Purifier :
I would suggest you to use the HTML Purifier for that:
好吧,你可以去掉所有不属于 URL 的字符
然后你可以检查它是否是一个有效的 URL
Well, you can get rid of all the characters that don't belong in a URL
Then you can check that it is a valid URL
你用代码做什么?执行它?
当您回显 php 代码时,无需担心服务器端...您宁愿执行 html_entity_encode 来防止您的网站被用户帖子搞乱或被 iframes/javascripts 注入
what are you doing with the code? execute it?
when you echo the php code theres no need to worry server side... you rather want to do html_entity_encode to keep your website from beeing messed up or beeing injected by iframes/javascripts by user posts