PHP-自行提交表单:$ _ SERVER ['PHP_SELF'] OR action =“""? [英] PHP - Self form submission: $_SERVER['PHP_SELF'] OR action=""?
问题描述
我只是意识到,在某些奇怪的情况下,我正在做我认为是自我提交的事情,而没有在action form属性上引用PHP_SELF.
I just realise that, for some weird circumstances, I was doing what I believe to be self submissions, without any reference to PHP_SELF on the action form attribute.
我很困惑,我们可以使用
I'm puzzled, can we either use
<?php echo filter_var($_SERVER['PHP_SELF'], FILTER_SANITIZE_STRING); ?>
或
action=""
?
如果不是,在什么情况下我们应该考虑一个或另一个?
If not, on what circumstances should we considered one, or another?
预先感谢, MEM
推荐答案
您可以使用(PHP_SELF或空字符串).但是为什么要为此使用FILTER_SANITIZE_STRING?在这种情况下,如果您的路径包含已过滤的字符,例如,最好使用 htmlentities()而不是filter_var <
),该表单将不会提交.
You can use either (PHP_SELF or empty string). but why would you use FILTER_SANITIZE_STRING for this? You'd better to use htmlentities() instead of filter_var in this case, if your path contains filtered characters (e.g. <
), the form won't submit.
我更喜欢提供一个字符串,使用空值时<base href=>
可能会引起麻烦.
示例:
I prefer giving a string, <base href=>
can cause trouble when using empty values.
Example:
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="post">
</form>
这篇关于PHP-自行提交表单:$ _ SERVER ['PHP_SELF'] OR action =“""?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!