Maison >développement back-end >tutoriel php >html - php文件无法得到POST过来的数据
php文件无法得到POST过来的数据,通过$_SERVER得到如下
<code>Array ( [HOSTNAME] => localhost.localdomain [PATH] => /usr/local/bin:/usr/bin:/bin [TMP] => /tmp [TMPDIR] => /tmp [TEMP] => /tmp [OSTYPE] => [MACHTYPE] => [MALLOC_CHECK_] => 2 [USER] => www [HOME] => /home/www [FCGI_ROLE] => RESPONDER [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_SOFTWARE] => nginx [QUERY_STRING] => [REQUEST_METHOD] => GET [CONTENT_TYPE] => [CONTENT_LENGTH] => [SCRIPT_FILENAME] => /data0/htdocs/www_v2/index/htdocs/index.php [SCRIPT_NAME] => /index.php [REQUEST_URI] => /tcenter/manage_type/saveunitc/ [DOCUMENT_URI] => /index.php [DOCUMENT_ROOT] => /data0/htdocs/www_v2/index/htdocs [SERVER_PROTOCOL] => HTTP/1.1 [REMOTE_ADDR] => 222.130.133.84 [REMOTE_PORT] => 11347 [SERVER_ADDR] => 118.145.8.49 [SERVER_PORT] => 80 [SERVER_NAME] => *.izton.com [REDIRECT_STATUS] => 200 [HTTP_HOST] => www.izton.com [HTTP_CONNECTION] => keep-alive [HTTP_CACHE_CONTROL] => max-age=0 [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31 [HTTP_REFERER] => http://www.izton.com/tcenter/manage_type/editunit.do?id=11016502&num=2 [HTTP_ACCEPT_ENCODING] => gzip,deflate,sdch [HTTP_ACCEPT_LANGUAGE] => zh-CN,zh;q=0.8 [HTTP_ACCEPT_CHARSET] => GBK,utf-8;q=0.7,*;q=0.3 [HTTP_COOKIE] => PHPSESSID=8bc85489738f33e8909973ab534d7c80; KF360_6971_LIVE=Y; KF360_6971_REFERER=; PHPSESSID=ecb96ff35d7e68bdc14ffcfcd12835dc; KF360_6971_INVITEDTIMES=2; KF360_6971_VISITID=5666977; uname=172474; upass=123456; rem=1; Hm_lvt_b63d9415462f064e5fda5749bda4808f=1369358159; Hm_lpvt_b63d9415462f064e5fda5749bda4808f=1369641967; formhash=03bc8587; VISITORID=5269925 [PHP_SELF] => /index.php [REQUEST_TIME] => 1369640508 [argv] => Array ( ) [argc] => 0 ) </code>
但是在做项目的时候其他模板post的数据都可以接受,打印其中一个可接受到post数据的$_server
<code>Array ( [HOSTNAME] => localhost.localdomain [PATH] => /usr/local/bin:/usr/bin:/bin [TMP] => /tmp [TMPDIR] => /tmp [TEMP] => /tmp [OSTYPE] => [MACHTYPE] => [MALLOC_CHECK_] => 2 [USER] => www [HOME] => /home/www [FCGI_ROLE] => RESPONDER [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_SOFTWARE] => nginx [QUERY_STRING] => [REQUEST_METHOD] => POST [CONTENT_TYPE] => application/x-www-form-urlencoded [CONTENT_LENGTH] => 199 [SCRIPT_FILENAME] => /data0/htdocs/www_v2/index/htdocs/index.php [SCRIPT_NAME] => /index.php [REQUEST_URI] => /tcenter/manage_type/saveUnit.do [DOCUMENT_URI] => /index.php [DOCUMENT_ROOT] => /data0/htdocs/www_v2/index/htdocs [SERVER_PROTOCOL] => HTTP/1.1 [REMOTE_ADDR] => 222.130.133.84 [REMOTE_PORT] => 10758 [SERVER_ADDR] => 118.145.8.49 [SERVER_PORT] => 80 [SERVER_NAME] => *.izton.com [REDIRECT_STATUS] => 200 [HTTP_HOST] => www.izton.com [HTTP_CONNECTION] => keep-alive [HTTP_CONTENT_LENGTH] => 199 [HTTP_CACHE_CONTROL] => max-age=0 [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 [HTTP_ORIGIN] => http://www.izton.com [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31 [HTTP_CONTENT_TYPE] => application/x-www-form-urlencoded [HTTP_REFERER] => http://www.izton.com/tcenter/manage_type/addUnit.do?gid=0&did=0&sid=0&tid=0 [HTTP_ACCEPT_ENCODING] => gzip,deflate,sdch [HTTP_ACCEPT_LANGUAGE] => zh-CN,zh;q=0.8 [HTTP_ACCEPT_CHARSET] => GBK,utf-8;q=0.7,*;q=0.3 [HTTP_COOKIE] => PHPSESSID=8bc85489738f33e8909973ab534d7c80; KF360_6971_LIVE=Y; KF360_6971_REFERER=; PHPSESSID=ecb96ff35d7e68bdc14ffcfcd12835dc; KF360_6971_INVITEDTIMES=2; KF360_6971_VISITID=5666977; uname=172474; upass=123456; rem=1; Hm_lvt_b63d9415462f064e5fda5749bda4808f=1369358159; Hm_lpvt_b63d9415462f064e5fda5749bda4808f=1369641967; formhash=03bc8587; VISITORID=5269925 [PHP_SELF] => /index.php [REQUEST_TIME] => 1369640436 [argv] => Array ( ) [argc] => 0 ) </code>
两者的不同之处 ‘HTTPCONTENTTYPE’与‘HTTPCONNECTION’,‘HTTPCACHE_CONTROL’,
模板来回看了n遍,也没找到错误 下面是无法post数据的模板
<code> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title></title> <script type="text/javascript" src="<!--%7B%24baseurl%7D-->/js/jquery.js"></script> <div class="nav3 mb10"> <ul class="cc" style="margin-left:20px;margin-top: 10px"> <li><a href="/tcenter/manage_type/manageunit.do">管理单元</a></li> </ul> </div> <form action="/tcenter/manage_type/saveunitc" method="post" onsubmit="return check();"> <input type="hidden" name="id" value="<!--{$mesunit.id}-->"> <table style="width:300px;"> <tr> <td>单元顺序:</td> <td> <select name="unitnum" id="unitnum"> <option value="0">请选择</option> <!--{foreach from=$unitnums key=key item=item}--> <option value="<!--{$key}-->">selected<!--{/if}-->><!--{$item}--> </option> <!--{/foreach}--> </select> </td> </tr> <tr> <td>单元名称:</td> <td><input type="text" name="name" id="name" value="123"></td> </tr> <tr> <td colspan="2"> <input type="submit" value="提交" class="inputs"> </td> </tr> </table> </form> </code>
php文件无法得到POST过来的数据,通过$_SERVER得到如下
<code>Array ( [HOSTNAME] => localhost.localdomain [PATH] => /usr/local/bin:/usr/bin:/bin [TMP] => /tmp [TMPDIR] => /tmp [TEMP] => /tmp [OSTYPE] => [MACHTYPE] => [MALLOC_CHECK_] => 2 [USER] => www [HOME] => /home/www [FCGI_ROLE] => RESPONDER [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_SOFTWARE] => nginx [QUERY_STRING] => [REQUEST_METHOD] => GET [CONTENT_TYPE] => [CONTENT_LENGTH] => [SCRIPT_FILENAME] => /data0/htdocs/www_v2/index/htdocs/index.php [SCRIPT_NAME] => /index.php [REQUEST_URI] => /tcenter/manage_type/saveunitc/ [DOCUMENT_URI] => /index.php [DOCUMENT_ROOT] => /data0/htdocs/www_v2/index/htdocs [SERVER_PROTOCOL] => HTTP/1.1 [REMOTE_ADDR] => 222.130.133.84 [REMOTE_PORT] => 11347 [SERVER_ADDR] => 118.145.8.49 [SERVER_PORT] => 80 [SERVER_NAME] => *.izton.com [REDIRECT_STATUS] => 200 [HTTP_HOST] => www.izton.com [HTTP_CONNECTION] => keep-alive [HTTP_CACHE_CONTROL] => max-age=0 [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31 [HTTP_REFERER] => http://www.izton.com/tcenter/manage_type/editunit.do?id=11016502&num=2 [HTTP_ACCEPT_ENCODING] => gzip,deflate,sdch [HTTP_ACCEPT_LANGUAGE] => zh-CN,zh;q=0.8 [HTTP_ACCEPT_CHARSET] => GBK,utf-8;q=0.7,*;q=0.3 [HTTP_COOKIE] => PHPSESSID=8bc85489738f33e8909973ab534d7c80; KF360_6971_LIVE=Y; KF360_6971_REFERER=; PHPSESSID=ecb96ff35d7e68bdc14ffcfcd12835dc; KF360_6971_INVITEDTIMES=2; KF360_6971_VISITID=5666977; uname=172474; upass=123456; rem=1; Hm_lvt_b63d9415462f064e5fda5749bda4808f=1369358159; Hm_lpvt_b63d9415462f064e5fda5749bda4808f=1369641967; formhash=03bc8587; VISITORID=5269925 [PHP_SELF] => /index.php [REQUEST_TIME] => 1369640508 [argv] => Array ( ) [argc] => 0 ) </code>
但是在做项目的时候其他模板post的数据都可以接受,打印其中一个可接受到post数据的$_server
<code>Array ( [HOSTNAME] => localhost.localdomain [PATH] => /usr/local/bin:/usr/bin:/bin [TMP] => /tmp [TMPDIR] => /tmp [TEMP] => /tmp [OSTYPE] => [MACHTYPE] => [MALLOC_CHECK_] => 2 [USER] => www [HOME] => /home/www [FCGI_ROLE] => RESPONDER [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_SOFTWARE] => nginx [QUERY_STRING] => [REQUEST_METHOD] => POST [CONTENT_TYPE] => application/x-www-form-urlencoded [CONTENT_LENGTH] => 199 [SCRIPT_FILENAME] => /data0/htdocs/www_v2/index/htdocs/index.php [SCRIPT_NAME] => /index.php [REQUEST_URI] => /tcenter/manage_type/saveUnit.do [DOCUMENT_URI] => /index.php [DOCUMENT_ROOT] => /data0/htdocs/www_v2/index/htdocs [SERVER_PROTOCOL] => HTTP/1.1 [REMOTE_ADDR] => 222.130.133.84 [REMOTE_PORT] => 10758 [SERVER_ADDR] => 118.145.8.49 [SERVER_PORT] => 80 [SERVER_NAME] => *.izton.com [REDIRECT_STATUS] => 200 [HTTP_HOST] => www.izton.com [HTTP_CONNECTION] => keep-alive [HTTP_CONTENT_LENGTH] => 199 [HTTP_CACHE_CONTROL] => max-age=0 [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 [HTTP_ORIGIN] => http://www.izton.com [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31 [HTTP_CONTENT_TYPE] => application/x-www-form-urlencoded [HTTP_REFERER] => http://www.izton.com/tcenter/manage_type/addUnit.do?gid=0&did=0&sid=0&tid=0 [HTTP_ACCEPT_ENCODING] => gzip,deflate,sdch [HTTP_ACCEPT_LANGUAGE] => zh-CN,zh;q=0.8 [HTTP_ACCEPT_CHARSET] => GBK,utf-8;q=0.7,*;q=0.3 [HTTP_COOKIE] => PHPSESSID=8bc85489738f33e8909973ab534d7c80; KF360_6971_LIVE=Y; KF360_6971_REFERER=; PHPSESSID=ecb96ff35d7e68bdc14ffcfcd12835dc; KF360_6971_INVITEDTIMES=2; KF360_6971_VISITID=5666977; uname=172474; upass=123456; rem=1; Hm_lvt_b63d9415462f064e5fda5749bda4808f=1369358159; Hm_lpvt_b63d9415462f064e5fda5749bda4808f=1369641967; formhash=03bc8587; VISITORID=5269925 [PHP_SELF] => /index.php [REQUEST_TIME] => 1369640436 [argv] => Array ( ) [argc] => 0 ) </code>
两者的不同之处 ‘HTTPCONTENTTYPE’与‘HTTPCONNECTION’,‘HTTPCACHE_CONTROL’,
模板来回看了n遍,也没找到错误 下面是无法post数据的模板
<code> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title></title> <script type="text/javascript" src="<!--%7B%24baseurl%7D-->/js/jquery.js"></script> <div class="nav3 mb10"> <ul class="cc" style="margin-left:20px;margin-top: 10px"> <li><a href="/tcenter/manage_type/manageunit.do">管理单元</a></li> </ul> </div> <form action="/tcenter/manage_type/saveunitc" method="post" onsubmit="return check();"> <input type="hidden" name="id" value="<!--{$mesunit.id}-->"> <table style="width:300px;"> <tr> <td>单元顺序:</td> <td> <select name="unitnum" id="unitnum"> <option value="0">请选择</option> <!--{foreach from=$unitnums key=key item=item}--> <option value="<!--{$key}-->">selected<!--{/if}-->><!--{$item}--> </option> <!--{/foreach}--> </select> </td> </tr> <tr> <td>单元名称:</td> <td><input type="text" name="name" id="name" value="123"></td> </tr> <tr> <td colspan="2"> <input type="submit" value="提交" class="inputs"> </td> </tr> </table> </form> </code>
感觉是个低级错误,你上边打出来的$server 里method 是GET ,提交get请求肯定没有$POST了
“
[REQUEST_METHOD] => GET
”