<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[刘新修]]></title> 
<link>http://pic1.liuxinxiu.com:80/index.php</link> 
<description><![CDATA[刘新修的个人博客 (Liuxinxiu'S Blog)]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[刘新修]]></copyright>
<item>
<link>http://pic1.liuxinxiu.com:80/php_http/</link>
<title><![CDATA[PHP处理HTTP请求的几种方式]]></title> 
<author>刘新修 &lt;admin@yourname.com&gt;</author>
<category><![CDATA[PHP/Java/Go]]></category>
<pubDate>Mon, 05 Sep 2016 09:48:38 +0000</pubDate> 
<guid>http://pic1.liuxinxiu.com:80/php_http/</guid> 
<description>
<![CDATA[ 
	<p><span style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', arial, 宋体, sans-serif, tahoma; line-height: 24px;">GET，一般是明文的，比如XXX.php?a=1&amp;b=2，这里的a，b就必须用GET方式接收，接收代码如下：</span><br style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', arial, 宋体, sans-serif, tahoma; line-height: 24px;" /><span style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', arial, 宋体, sans-serif, tahoma; line-height: 24px;">$a = $_GET['a'];</span><br style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', arial, 宋体, sans-serif, tahoma; line-height: 24px;" /><span style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', arial, 宋体, sans-serif, tahoma; line-height: 24px;">$b = $_GET['b'];</span><br style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', arial, 宋体, sans-serif, tahoma; line-height: 24px;" /><span style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', arial, 宋体, sans-serif, tahoma; line-height: 24px;">//接收a,b两个变量</span><br style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', arial, 宋体, sans-serif, tahoma; line-height: 24px;" /><span style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', arial, 宋体, sans-serif, tahoma; line-height: 24px;">POST，一般是隐藏的非明文的，一般表单设置成POST的，接收方式如下：</span><br style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', arial, 宋体, sans-serif, tahoma; line-height: 24px;" /><span style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', arial, 宋体, sans-serif, tahoma; line-height: 24px;">//比如有个表单，表单中有两个文本框，name 分别是 a,b，那么代码如下：</span><br style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', arial, 宋体, sans-serif, tahoma; line-height: 24px;" /><span style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', arial, 宋体, sans-serif, tahoma; line-height: 24px;">$a = $_POST['a'];</span><br style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', arial, 宋体, sans-serif, tahoma; line-height: 24px;" /><span style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', arial, 宋体, sans-serif, tahoma; line-height: 24px;">$b = $_POST['b'];</span><br style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', arial, 宋体, sans-serif, tahoma; line-height: 24px;" /><span style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', arial, 宋体, sans-serif, tahoma; line-height: 24px;">另外：$_REQUEST，可以同时接收GET、PO</span><span style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', arial, 宋体, sans-serif, tahoma; line-height: 24px;">ST的变量，用法如：</span><br style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', arial, 宋体, sans-serif, tahoma; line-height: 24px;" /><span style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei', arial, 宋体, sans-serif, tahoma; line-height: 24px;">$_REQUEST['a'];//接收变量a，a可以是GET的也可以是POST的</span></p><p><span style="color: rgb(255, 0, 0);"><strong>另外说说PHP获取POST请求的几种方式：</strong></span></p><pre id="best-content-2323710466" accuse="aContent" class="best-text mb-10" style="margin-top: 10px; margin-bottom: 10px; padding: 0px; font-family: 'Microsoft YaHei', arial, 'courier new', courier, 宋体, monospace; white-space: pre-wrap; word-wrap: break-word; line-height: 26px; color: rgb(51, 51, 51); min-height: 55px;">方法1、最常见的方法是：$_POST['fieldname'];<br />说明：只能接收Content-Type: application/x-www-form-urlencoded提交的数据<br />解释：也就是表单POST过来的数据<br /> <br />方法2、file_get_contents(&ldquo;php://input&rdquo;);<br />说明：<br />允许读取 POST 的原始数据。<br />和 $HTTP_RAW_POST_DATA 比起来，它给内存带来的压力较小，并且不需要任何特殊的 <a href="https://www.baidu.com/s?wd=php.ini&amp;tn=44039180_cpr&amp;fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1Y3rH63mWw9nWuhP1cLrAP-0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHfYP1D4nWDYnW0vnH0vPWmzn0" target="_blank" class="baidu-highlight" rel="nofollow" style="color: rgb(63, 136, 191); text-decoration: none;">php.ini</a> 设置。<br />php://input 不能用于 enctype=&rdquo;multipart/form-data&rdquo;。<br />解释：<br />对于未指定 Content-Type 的POST数据，则可以使用file_get_contents(&ldquo;php://input&rdquo;);来获取原始数据。<br />事实上，用PHP接收POST的任何数据都可以使用本方法。而不用考虑Content-Type,包括二进制文件流也可以。<br />所以用方法二是最保险的方法。<br /> <br />方法3、$GLOBALS['HTTP_RAW_POST_DATA'];<br />说明：<br />总是产生 $HTTP_RAW_POST_DATA&nbsp;&nbsp;变量包含有原始的 POST 数据。<br />此变量仅在碰到未识别 MIME 类型的数据时产生。<br />$HTTP_RAW_POST_DATA&nbsp;&nbsp;对于 enctype=&rdquo;multipart/form-data&rdquo;&nbsp;&nbsp;表单数据不可用<br />如果post过来的数据不是PHP能够识别的，可以用 $GLOBALS['HTTP_RAW_POST_DATA']来接收，<br />比如 text/xml 或者 soap 等等<br />解释：<br />$GLOBALS['HTTP_RAW_POST_DATA']存放的是POST过来的原始数据。<br />$_POST或$_REQUEST存放的是 PHP以key=&gt;value的形式格式化以后的数据。<br />但$GLOBALS['HTTP_RAW_POST_DATA']中是否保存POST过来的数据取决于centent-Type的设置，即POST数据时 必须显式示指明Content-Type: application/x-www-form-urlencoded，POST的数据才会存放到 $GLOBALS['HTTP_RAW_POST_DATA']中。</pre><br/>Tags - <a href="http://pic1.liuxinxiu.com:80/tags/php/" rel="tag">php</a>
]]>
</description>
</item><item>
<link>http://pic1.liuxinxiu.com:80/php_http/#blogcomment</link>
<title><![CDATA[[评论] PHP处理HTTP请求的几种方式]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://pic1.liuxinxiu.com:80/php_http/#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>