$ _POST,$ _GET和$ _REQUEST为空 [英] $_POST, $_GET and $_REQUEST Empty

查看:180
本文介绍了$ _POST,$ _GET和$ _REQUEST为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已解决:我省略了输入字段中的名称属性。
我有一个简单的html / php -form。我提交它。 $ _POST总是空的。如果我尝试get,那么GET总是空的。 $ _REQUEST和php://输入相同。我没有得到任何回报。

有很多这个主题的帖子,但我还没有找到解决我的问题。我没有重写或重定向。 method_request是POST。在表单中没有id冲突,
php://输入也是空的,REQUEST也是空的。我已经把Suhosin.simulation放在了上面,这意味着它不起作用。 POST_MAX_SIZE = 16M。对于两个小文本应该足够了。

php.ini变量request_order和variable_order分别是GP和GPS。 Magic_quotes_gpc已关闭。默认mime-type = text / html,每个页面都有字符集UTF-8。
php_sapi_name()函数的结果是apache2handler。



PHPVersion = 5.3,Suhosin - patch 0.9.1。 OS = Ubuntu 12.04 LTS,Apache = 2.2.22。



这里有两个文件。我简化了他们一些,但通常他们工作没有任何问题。

 <?php 

$ tmpHeader = <!DOCTYPE html>< html>< head> \\\
;
$ tmpHeader。=< meta charset = \UTF-8 \>< meta http-equiv = \Content-Type \content = \application / x- WWW窗体-urlencoded;字符集= UTF-8\ > \\\
;
$ tmpHeader。=< title> testPost< / title> \\\
;
$ tmpHeader。=< link rel = \stylesheet \href = \/css/layout.css\> \\\
;
$ tmpHeader。=< link rel = \stylesheet \href = \/css/semantics.css\> \\\
;
$ tmpHeader。=< link rel = \stylesheet \href = \/css/defaults.css\> \\\
;
$ tmpHeader。=< / head>;

$ tmpBody =< body id = \defaultBody \>< section id = \page\> \\\
;
$ tmpBody。=< div id = \container \> \\\
;
$ tmpBody。=< form id = \pagewrap \name = \pagewrap\method = \POST \action = \http:// www。 thuis.lb/testPost_2.phpenctype = \application / x-www-form-urlencoded\> \\\
;
$ tmpBody。=< input type = \hidden \id = \context_id \value = \testPost \> \\\
;
$ tmpBody。=< header id = \pageHeader \> \\\
;
$ tmpBody。=< div id = \leftHeader \>< img src = \。clientSideImages。Homerus.jpg\\alt = \homerus \ >< / DIV> \\\
;
$ tmpBody。=< div id = \centralHeader \>< h1> Slogan< / h1>< / div> \\\
;
$ tmpBody。=< / header> \\\
;

$ pageData =< section id = \doc_content\> \\\
;
$ pageData。=< fieldset><图例> testPost< / legend> \\\
;
$ pageData。=< div class = \fourcolumns_odd \>< label for = \username \>用户名< / label>< / div> \\\
;
$ pageData。=< div class = \fourcolumns_even \>< input type = \text \id = \username \value = \\\ \\ >< / DIV> \\\
;
$ pageData。=< div class = \fourcolumns_odd\>< label for = \password \>密码< / label>< / div> \\\
;
$ pageData。=< div class = \fourcolumns_even \>< input type = \text \id = \password \value = \\\ \\ >< / DIV> \\\
;
$ pageData。=< div class = \onecolumn \>< input type = \submit \id = \submitButton \value = \inloggen \ >< / DIV> \\\
;
$ pageData。=< / fieldset> \\\
;
$ pageData。=< input type = \hidden \id = \passwordHash \value = \\> \\\
;
$ pageData。=< / section><! - section of section doc_content - > \\\
的结尾;
$ tmpBody。=< div id = \leftWing\>< img src = \。clientSideImages。IronPillarDelphi.jpg \alt = \homerus \ >< / DIV> \\\
;
$ tmpBody。=< div id = \centerField \class = \centerVertically \>。$ pageData。< / div> \\\
;
$ tmpBody。=< div id = \rightWing\>< img src = \。clientSideImages。IronPillarDelphi.jpg \alt = \homerus \ >< / DIV> \\\
;
$ tmpBody。=< / form> \\\
;
$ tmpBody。=< / div><! - 容器结束 - > \\\
;
$ tmpBody。=< / section><! - 页尾 - > \\\
;
$ tmpBody。=< / body>< / html> \\\
;

logStatement('requestheaders:');
$ testpostdata = file_get_contents(php:// input);
log_r($ testpostdata);

print $ tmpHeader。$ tmpBody;
?>

$ _POST数据应该发送到的另一个文件:

 <!DOCTYPE html>< html>< head> 
< meta charset =UTF-8> < meta http-equiv =Content-Typecontent =application / x-www-form-urlencoded; charset = utf-8>
< title> testPost_II< / title>
< link rel =stylesheethref =/ css / layout.css>
< link rel =stylesheethref =/ css / semantics.css>
< link rel =stylesheethref =/ css / defaults.css>
< / head>< body id =defaultBody>< section id =page>
< div id =container>
< header id =pageHeader>
< div id =leftHeader>< img src =/ images / Homerus.jpgalt =homerus>< / div>
< div id =centralHeader>< h1>口号< / h1>< span>特别><?php print getValue('username','nothing found');?> ;< /跨度>< / DIV>
< / header>
< div id =leftWing>< img src =/ images / IronPillarDelphi.jpgalt =homerus>< / div>
< div id =center_Fieldclass =centerVertically>< section id =doc_content>
< input type =textid =context_idvalue =<?php var_dump($ _ POST);?>>
< fieldset><图例> testPost_2< / legend>
< div class =fourcolumns_odd>< label for =username> username< / label>< / div>
< div class =fourcolumns_even>< input type =textid =usernamevalue =<?php print getValue('username','Noname');?> >< / DIV>
< div class =fourcolumns_odd>< label for =password> password< / label>< / div>
< div class =fourcolumns_even>< input type =textid =passwordvalue =<?php echo getValue('password','Secret');?> >< / DIV>
< div class =fourcolumns_odd>< label for =request_method>请求方法< / label>< / div>
< div class =fourcolumns_even>< input type =textid =usernamevalue =<?php print $ _SERVER ['REQUEST_METHOD'];?>><<< ; / DIV>
< div class =onecolumn>< input type =submitid =submitButtonvalue =inloggen>< / div>
< / fieldset>
< / section><! - section的结尾doc_content - >
< / div>
< div id =rightWing>< img src =/ images / IronPillarDelphi.jpgalt =homerus>< / div>
< / form>
< / div><! - 容器结束 - >
< / section><! - 页尾 - >
< / body>< / html>



是本地服务器的名称。它有IP 127.0.0.1。在家里Thuis是荷兰人。
有什么我忘记了或者我做错了吗?



编辑:一些更多信息。
在更复杂的第一个php中,有一个与数据库交换信息。这就像一个魅力。没有问题。
因此我认为这个问题是一个安全问题。我将为www.thuis.lb添加虚拟主机文件。虽然它几乎像默认的虚拟主机,但它可能是问题所在。

 < VirtualHost thuis.lb:80> 
ServerName www.thuis.lb
ServerAlias thuis.lb * .thuis.lb
ServerAdmin lbergman@loekbergman.nl
DocumentRoot / var / www / thuis
RewriteEngine On
RewriteOptions继承

<目录/ var / www / thuis />
选项索引FollowSymLinks MultiViews
AllowOverride全部
允许所有
允许,拒绝
$< / Directory>

ScriptAlias / cgi-bin / usr / lib / cgi-bin /
< Directory/ usr / lib / cgi-bin>
AllowOverride无
选项+ ExecCGI -MultiViews + SymLinksIfOwnerMatch
允许,拒绝
所有
允许< / Directory>

ErrorLog /var/log/apache2/thuis/error.log

#可能的值包括:debug,info,notice,warn,error,crit,
警惕,emerg。
LogLevel debug

CustomLog /var/log/apache2/thuis/access.log合并

Alias / doc // usr / share / doc /
<目录/ usr / share / doc />
选项索引MultiViews FollowSymLinks
AllowOverride None
拒绝所有
拒绝所有
允许从127.0.0.0/255.0.0.0 :: 1/128
< / Directory>
< / VirtualHost>

编辑二:我可以添加更多信息。在访问日志中有这样一行:
127.0.0.1 - - [04 / Apr / 2013:11:13:43 +0200]POST /testPost_2.php HTTP / 1.1200 2020 http://www.thuis.lb/testPost.php Mozilla / 5.0(X11; Ubuntu; Linux x86_64; rv:19.0)Gecko / 20100101 Firefox / 19.0。这显示了apache2正在以良好的顺序接收该帖子。但PHP中的$ _POST仍然是完全空的。
在Firebug> Net> Headers的显示内容长度为0。

解决方案

一个名称属性或只是一个ID属性?

 < input type =textid =这可能与为每个输入字段添加名称属性一样简单。 afieldvalue =a value> 

不同于

 < input type =textid =afieldname =afieldvalue =a value> 

$ _ POST ['afield']应该只返回上面第二个示例的值


SOLVED: I omitted the name attribute on the input fields. I have a simple html/php -form. And I submit it. The $_POST is always empty. If I try a get then the GET is always empty. Same for $_REQUEST and php://input. I get nothing in return.

There a lot of posts with this subject, yet I have not found the solution for my problem. I do not have a rewrite or redirect. The method_request is POST. There is no clash with id's in the form, php://input is empty as well, REQUEST is empty as well. I have put Suhosin.simulation to on, which means that it is not working. POST_MAX_SIZE = 16M. Should be sufficient for two small texts.

The php.ini variables request_order and variable_order are GP and GPS respectively. Magic_quotes_gpc is Off. Default mime-type = text/html and every page has charset UTF-8. Result of the function php_sapi_name() is apache2handler.

PHPVersion = 5.3, Suhosin - patch 0.9.1. OS = Ubuntu 12.04 LTS, Apache = 2.2.22.

Here are two files. I have simplified them a little, but normally they work without any problem. I have similar files for the GET-method.

<?php

$tmpHeader = "<!DOCTYPE html><html><head>\n";
$tmpHeader .= "<meta charset=\"UTF-8\"> <meta http-equiv=\"Content-Type\" content=\"application/x-www-form-urlencoded; charset=utf-8\">\n";
$tmpHeader.= "<title>testPost</title>\n";
$tmpHeader.= "<link rel=\"stylesheet\" href=\"/css/layout.css\">\n";
$tmpHeader.= "<link rel=\"stylesheet\" href=\"/css/semantics.css\">\n";
$tmpHeader.= "<link rel=\"stylesheet\" href=\"/css/defaults.css\">\n";
$tmpHeader.="</head>";

$tmpBody = "<body id=\"defaultBody\"><section id=\"page\">\n";
$tmpBody .= "<div id=\"container\">\n";
$tmpBody .= "<form id=\"pagewrap\" name=\"pagewrap\" method=\"POST\" action=\"http://www.thuis.lb/testPost_2.php\" enctype=\"application/x-www-form-urlencoded\">\n";
$tmpBody .= "<input type=\"hidden\" id=\"context_id\" value=\"testPost\">\n";
$tmpBody.="<header id=\"pageHeader\">\n";
$tmpBody.="<div id=\"leftHeader\"><img src=\"".clientSideImages."Homerus.jpg\" alt=\"homerus\"></div>\n";
$tmpBody.="<div id=\"centralHeader\"><h1>Slogan</h1></div>\n";
$tmpBody.="</header>\n";

$pageData = "<section id=\"doc_content\">\n";
$pageData.= "<fieldset><legend>testPost</legend>\n";
$pageData.= "<div class=\"fourcolumns_odd\"><label for=\"username\">username</label></div>\n";
$pageData.= "<div class=\"fourcolumns_even\"><input type=\"text\" id=\"username\" value=\"\"></div>\n";
$pageData.= "<div class=\"fourcolumns_odd\"><label for=\"password\">password</label></div>\n";
$pageData.= "<div class=\"fourcolumns_even\"><input type=\"text\" id=\"password\" value=\"\"></div>\n";
$pageData.= "<div class=\"onecolumn\"><input type=\"submit\" id=\"submitButton\" value=\"inloggen\"></div>\n";
$pageData.= "</fieldset>\n";
$pageData.= "<input type=\"hidden\" id=\"passwordHash\" value=\"\">\n";
$pageData.="</section><!--end of section doc_content -->\n";
$tmpBody .= "<div id=\"leftWing\"><img src=\"".clientSideImages."IronPillarDelphi.jpg\" alt=\"homerus\"></div>\n";
$tmpBody.= "<div id=\"centerField\" class=\"centerVertically\">".$pageData."</div>\n";
$tmpBody.= "<div id=\"rightWing\"><img src=\"".clientSideImages."IronPillarDelphi.jpg\" alt=\"homerus\"></div>\n";
$tmpBody.="</form>\n";
$tmpBody.= "</div><!-- end of container -->\n";
$tmpBody.="</section><!-- end of page -->\n";
$tmpBody.="</body></html>\n";

logStatement('requestheaders: ');
$testpostdata = file_get_contents("php://input");
log_r($testpostdata);

print $tmpHeader.$tmpBody;
?>

The other file to which the $_POST data should be sent:

<!DOCTYPE html><html><head>
<meta charset="UTF-8"> <meta http-equiv="Content-Type" content="application/x-www-form-urlencoded; charset=utf-8">
<title>testPost_II</title>
<link rel="stylesheet" href="/css/layout.css">
<link rel="stylesheet" href="/css/semantics.css">
<link rel="stylesheet" href="/css/defaults.css">
</head><body id="defaultBody"><section id="page">
<div id="container">
<form id="pagewrap" name="pagewrap" method="POST" action="http://www.thuis.lb/testPost.php" enctype="application/x-www-form-urlencoded">
<header id="pageHeader">
<div id="leftHeader"><img src="/images/Homerus.jpg" alt="homerus"></div>
<div id="centralHeader"><h1>Slogan</h1><span>Special for ><?php print getValue('username','nothing found');?></span></div>
</header>
<div id="leftWing"><img src="/images/IronPillarDelphi.jpg" alt="homerus"></div>
<div id="centerField" class="centerVertically"><section id="doc_content">
<input type="text" id="context_id" value="<?php var_dump($_POST);?>">
<fieldset><legend>testPost_2</legend>
<div class="fourcolumns_odd"><label for="username">username</label></div>
<div class="fourcolumns_even"><input type="text" id="username" value="<?php print     getValue('username','Noname');?>"></div>
<div class="fourcolumns_odd"><label for="password">password</label></div>
<div class="fourcolumns_even"><input type="text" id="password" value="<?php echo getValue('password','Secret');?>"></div>
<div class="fourcolumns_odd"><label for="request_method">request method</label></div>
<div class="fourcolumns_even"><input type="text" id="username" value="<?php print $_SERVER['REQUEST_METHOD'];?>"></div>
<div class="onecolumn"><input type="submit" id="submitButton" value="inloggen"></div>
</fieldset>
</section><!--end of section doc_content -->
</div>
<div id="rightWing"><img src="/images/IronPillarDelphi.jpg" alt="homerus"></div>
</form>
</div><!-- end of container -->
</section><!-- end of page -->
</body></html>

www.thuis.lb is a name of a local server. It has IP 127.0.0.1. Thuis is Dutch for at home. Is there anything that I have forgotten or that I am doing wrong?

EDIT: Some more information. In the more complex first php there is an exchange of information with a database. That works like a charm. No problem at all. Therefor do I think that the problem is a security issue. I will add the virtual host file for www.thuis.lb. Although it is almost like the default virtualhost, it might be the problem.

<VirtualHost thuis.lb:80>
    ServerName www.thuis.lb
    ServerAlias thuis.lb *.thuis.lb
    ServerAdmin lbergman@loekbergman.nl
    DocumentRoot /var/www/thuis
    RewriteEngine On
    RewriteOptions Inherit

<Directory /var/www/thuis/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog /var/log/apache2/thuis/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug

CustomLog /var/log/apache2/thuis/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>

EDIT II: I can add more information. In the access log there is for instance this line: 127.0.0.1 - - [04/Apr/2013:11:13:43 +0200] "POST /testPost_2.php HTTP/1.1" 200 2020 "http://www.thuis.lb/testPost.php" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0". That shows imo that apache2 is receving the post in good order. But the $_POST in PHP is still completely empty. In the display of Firebug>Net>Headers is Content Length 0.

解决方案

Do all your form input fields have a name attribute or just an id attribute? It might be as simple as adding a name attribute to each input field.

<input type="text" id="afield" value="a value">

Is not the same as

<input type="text" id="afield" name="afield" value="a value">

$_POST['afield'] should only return a value with the second example above

这篇关于$ _POST,$ _GET和$ _REQUEST为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆