PHP $_POST vari...LOGIN

PHP $_POST variable

PHP $_POST variable

In PHP, the predefined $_POST variable is used to collect values ​​from the form with method="post".

$_POST variable

The predefined $_POST variable is used to collect forms from method="post" value in .

Information sent from a form with the POST method is invisible to anyone (will not be displayed in the browser's address bar), and there is no limit on the amount of information sent.

Note: However, by default, the maximum amount of information sent by the POST method is 8 MB (can be changed by setting post_max_size in the php.ini file).

Example

form.html file code is as follows:

<html>
<head>
<meta charset="utf-8">
<title>php中文网(php.cn)</title>
</head>
<body>
 
<form action="welcome.php" method="post">
名字: <input type="text" name="fname">
年龄: <input type="text" name="age">
<input type="submit" value="提交">
</form>
 
</body>
</html>

When the user clicks the "Submit" button, the URL is similar to the following:

form1.gif

When to use method="post"?

Information sent from a form with the POST method is invisible to anyone, and there is no limit on the amount of information sent.

However, since the variable does not appear in the URL, the page cannot be bookmarked.

PHP $_REQUEST variable

The predefined $_REQUEST variable contains the contents of $_GET, $_POST and $_COOKIE.

$_REQUEST variable can be used to collect form data sent via GET and POST methods.

Example

You can modify the "welcome.php" file to the following code, which can accept $_GET, $_POST and other data.

Welcome<?php echo $_REQUEST["fname"]; ?>!<br>

Your age is<?php echo $_REQUEST["age"] ; ?> Years old.

The difference between GET and POST value transfer methods:

1. Get adds the data in the form to the form in the form of variable=value. Behind the URL pointed to by the action, and the two are connected using "?", and each variable is connected using "&"; Post puts the data in the form in the data body of the form, according to the corresponding way of variables and values. , passed to the URL pointed to by the action.

2, Get is unsafe because during the transmission process, the data is placed in the requested URL, and many existing servers, proxy servers or user agents will record the request URL in log files. , and then put it somewhere so that some private information may be seen by a third party. In addition, users can also see the submitted data directly on the browser, and some internal system messages will be displayed in front of the user. All Post operations are invisible to users.

3. The amount of data transferred by Get is small, mainly because it is limited by the URL length; while Post can transfer a large amount of data, so only Post can be used to upload files (of course there is another reason, which will be discussed later) mentioned).

4, Get restricts the value of the data set in the Form form to be ASCII characters; while Post supports the entire ISO10646 character set.

5, Get is the default method of Form.

Next Section
PHP $_POST 变量 ________________________________________ 在 PHP 中,预定义的 $_POST 变量用于收集来自 method="post" 的表单中的值。 ________________________________________ $_POST 变量 预定义的 $_POST 变量用于收集来自 method="post" 的表单中的值。 从带有 POST 方法的表单发送的信息,对任何人都是不可见的(不会显示在浏览器的地址栏),并且对发送信息的量也没有限制。 注释:然而,默认情况下,POST 方法的发送信息的量最大值为 8 MB(可通过设置 php.ini 文件中的 post_max_size 进行更改)。 实例 form.html 文件代码如下: <html> <head> <meta charset="utf-8"> <title>php中文网(php.cn)</title> </head> <body> <form action="welcome.php" method="post"> 名字: <input type="text" name="fname"> 年龄: <input type="text" name="age"> <input type="submit" value="提交"> </form> </body> </html> 当用户点击 "提交" 按钮时,URL 类似如下所示: //m.sbmmt.com/welcome.php "welcome.php" 文件现在可以通过 $_POST 变量来收集表单数据了(请注意,表单域的名称会自动成为 $_POST 数组中的键): 欢迎 <?php echo $_POST["fname"]; ?>!<br> 你的年龄是 <?php echo $_POST["age"]; ?> 岁。 ________________________________________ 何时使用 method="post"? 从带有 POST 方法的表单发送的信息,对任何人都是不可见的,并且对发送信息的量也没有限制。 然而,由于变量不显示在 URL 中,所以无法把页面加入书签。 ________________________________________ PHP $_REQUEST 变量 预定义的 $_REQUEST 变量包含了 $_GET、$_POST 和 $_COOKIE 的内容。 $_REQUEST 变量可用来收集通过 GET 和 POST 方法发送的表单数据。 实例 你可以将 "welcome.php" 文件修改为如下代码,它可以接受 $_GET、$_POST等数据。 欢迎 <?php echo $_REQUEST["fname"]; ?>!<br> 你的年龄是 <?php echo $_REQUEST["age"]; ?> 岁。 GET和POST传值方式的区别: 1,Get将表单中数据的按照variable=value的形式,添加到action所指向的URL后面,并且两者使用“?”连接,而各个变量之间使用“&”连接;Post是将表单中的数据放在form的数据体中,按照变量和值相对应的方式,传递到action所指向URL。 2,Get是不安全的,因为在传输过程,数据被放在请求的URL中,而如今现有的很多服务器、代理服务器或者用户代理都会将请求URL记录到日志文件中,然后放在某个地方,这样就可能会有一些隐私的信息被第三方看到。另外,用户也可以在浏览器上直接看到提交的数据,一些系统内部消息将会一同显示在用户面前。Post的所有操作对用户来说都是不可见的。 3,Get传输的数据量小,这主要是因为受URL长度限制;而Post可以传输大量的数据,所以在上传文件只能使用Post(当然还有一个原因,将在后面的提到)。 4,Get限制Form表单的数据集的值必须为ASCII字符;而Post支持整个ISO10646字符集。 5,Get是Form的默认方法。
submitReset Code
ChapterCourseware