形成简单的动作而不是更复杂 [英] Form simple action vs. more complicated

查看:62
本文介绍了形成简单的动作而不是更复杂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你有一个名为MyPage.php的页面,其中包含一个由同一页面处理的表单。

只需定义动作如

You have a page called MyPage.php containing a form that is handled by the same page.
What is the difference when you simply define action like

action="MyPage.php"



当你这样做时


and when you do it like

action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>"



哪一个更安全?


and Which one is more secure?

推荐答案

_SERVER [ < span class =code-string> PHP_SELF]); ?>
_SERVER["PHP_SELF"]); ?>"



哪一个更安全?


and Which one is more secure?


使用PHP_SELF的优点是,如果您重命名页面,您的操作属性也会更改。



关于安全性:使用 htmlspecialchars htmlentities ,它们具有相同的安全性。但是如果你没有使用PHP_SELF转义HTML字符,有一些漏洞利用 [ ^ ]。



就个人而言,我建议使用
The advantage of using PHP_SELF is that if you rename your page, your action attribute also changes.

About the security: with htmlspecialchars or htmlentities, they have the same security. But if you don't escape HTML characters with PHP_SELF, there are some exploits[^].

Personally, I suggest using


_SERVER [SCRIPT_NAME] 。如果更新文件名,则action属性将更新为,使用SCRIPT_NAME,您不会有使用PHP_SELF进行攻击的风险。
_SERVER["SCRIPT_NAME"]. If you update your filename, then the action attribute will update to, and with SCRIPT_NAME, you don't have the risk of the exploits with PHP_SELF.


这篇关于形成简单的动作而不是更复杂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆