首页 > 开发 > PHP > 正文

php $_POST 与 php://input的区别分析

2024-05-04 21:48:49
字体:
来源:转载
供稿:网友
$_POST 与 php教程://input可以取到值,$HTTP_RAW_POST_DATA 为空
$_POST 以关联数组方式组织提交的数据,并对此进行编码处理,如urldecode,甚至编码转换
php://input 也可以实现此这个功能可以获得POST的原始数据。
代码
echo   file_get_contents( "php://input ");
实例
 
<form action="post.php" method="post"> 
<input type="text" name="user"> 
<input type="password" name="password"> 
<input type="submit"> 
</form>
post.php
 
<? echo file_get_contents("php://input");?>
 
php://input 允许读取 POST 的原始数据。和 $HTTP_RAW_POST_DATA 比起来,它给内存带来的压力较小,并且不需要任何特殊的 php.ini 设置。php://input 不能用于 enctype="multipart/form-data"。
php $_POST

$_POST 变量是一个数组,内容是由 HTTP POST 方法发送的变量名称和值.

$_POST 变量用于收集来自 method="post" 的表单中的值,从带有 POST 方法的表单发送的信息,对任何人都是不可见的(不会显示在浏览器的地址栏),并且对发送信息的量也没有限制.

html

  1. <form action="welcome.php" method="post"> 
  2. Enter your name: <input type="text" name="name" /> 
  3. Enter your age: <input type="text" name="age" /> 
  4. <input type="submit" /> 
  5. </form>//开源代码Vevb.com 

welcome.php

Welcome <?php echo $_POST["name"]; ?>.<br />

You are <?php echo $_POST["age"]; ?> years old!

通过 HTTP POST 发送的变量不会显示在 URL 中,变量没有长度限制.

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表