为什么使用 $_SERVER['PHP_SELF'] 而不是“"? [英] Why use $_SERVER['PHP_SELF'] instead of ""

查看:30
本文介绍了为什么使用 $_SERVER['PHP_SELF'] 而不是“"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 PHP 页面上的表单中,您可以使用:

In a form on a PHP page, you can use:

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" ...>

<form action="#" ...>

<form action="" ...>

在表单的 action 属性中.由于 echo $_SERVER['PHP_SELF'] 没有传递使用 GET 的变量,你必须使用 "",你为什么要使用它还是 "#"?

in the action attribute of the form. Since echo $_SERVER['PHP_SELF'] does not pass variables for using GET and you have to use "", why would you use that or "#"?

我之所以这么问是因为我花了一些时间才弄清楚变量不是通过 $_SERVER['PHP_SELF'] 传递的.谢谢.

I'm asking because it took me some time to figure out that the variables are not passed with $_SERVER['PHP_SELF']. Thanks.

推荐答案

action 属性将默认为当前 URL.说将表单提交到它来自的同一个地方"是最可靠和最简单的方式.

The action attribute will default to the current URL. It is the most reliable and easiest way to say "submit the form to the same place it came from".

没有理由使用$_SERVER['PHP_SELF'],而且#根本不提交表单(除非有submit 附加的处理提交的事件处理程序).

There is no reason to use $_SERVER['PHP_SELF'], and # doesn't submit the form at all (unless there is a submit event handler attached that handles the submission).

这篇关于为什么使用 $_SERVER['PHP_SELF'] 而不是“"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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