<strong>$POST 、$HTTP_RAW_POST_DATA、php://input三者之间的区别</strong></span></span>
总是产生变量包含有原始的 POST 数据。否则,此变量仅在碰到未识别 MIME 类型的数据时产生。不过,访问原始 POST 数据的更好方法是 php://input。$HTTP_RAW_POST_DATA 对于 enctype="multipart/form-data" 表单数据不可用。 问题: $HTTP_RAW_POST_DATA == $_POST 吗?答案是为否。<strong>个人理解总结是这么玩的:</strong></span>
<span style="font-size:18px;">1:$POST我们常用的就不用介绍了吧</span>
<span style="font-size:18px;"></span>
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="font-size:18px;">2:$GLOBALS['HTTP_RAW_POST_DATA']:</span></span>
<span style="font-size:18px;"> 基本上$GLOBALS['HTTP_RAW_POST_DATA'] 和 $_POST是一样的。但是如果post过来的数据不是PHP能够识别的,你可以用 $GLOBALS['HTTP_RAW_POST_DATA']来接收,比如 text/xml 或者 soap 等等。PHP默认识别的数据类型是application/x-www.form-urlencoded标准的数据类型,用Content-Type=text/xml 类型,提交一个xml文档内容给了php server,要怎么获得这个POST数据。 The RAW / uninterpreted HTTP POST information can be accessed with: $GLOBALS['HTTP_RAW_POST_DATA'] This is useful in cases where the post Content-Type is not something PHP understands (such as text/xml).由于PHP默认只识别application/x-www.form-urlencoded标准的数据类型,因此,对型如text/xml的内容无法解析为$_POST数组,故保留原型,交给$GLOBALS['HTTP_RAW_POST_DATA'] 来接收。</span>
<span style="font-size:18px;">3:php://input 也可以实现此这个功能:<span style="white-space:pre"> </span>php://input 允许读取 POST 的原始数据。和 $HTTP_RAW_POST_DATA 比起来,它给内存带来的压力较小,并且不需要任何特殊的 php.ini 设置。php://input 不能用于 enctype="multipart/form-data"。例子:leyangjun.html<form action="leyangjun.php" method="post"> <p>first name: <input type="text" name="fname" /></p> <p>Last name: <input type="text" name="lname" /></p>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/ai/1169">
<img src="https://img.php.cn/upload/ai_manual/000/000/000/175680099816784.png" alt="美间AI">
</a>
<div class="aritcle_card_info">
<a href="/ai/1169">美间AI</a>
<p>美间AI:让设计更简单</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="美间AI">
<span>45</span>
</div>
</div>
<a href="/ai/1169" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="美间AI">
</a>
</div>
<input type="submit" value="Submit" /></form>leyangjun.php:<?php<span style="white-space:pre"> </span>echo "<pre class="brush:php;toolbar:false;">";<span style="white-space:pre"> </span>print_r($_POST);<span style="white-space:pre"> </span>$data = file_get_contents('php://input'); //都要解下码<span style="white-space:pre"> </span>print_r(urldecode($data));<span style="white-space:pre"> </span>echo "<br>";<span style="white-space:pre"> </span>print_r(urldecode($GLOBALS['HTTP_RAW_POST_DATA']));?></span>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号