$ _POST,$ _GET和$ _REQUEST空

时间:2013-04-03 00:32:51

标签: php post get apache2.2

已解决:我在输入字段中省略了name属性。 我有一个简单的html / php -form。我提交了它。 $ _POST始终为空。如果我尝试获取,则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,每个页面都有charset UTF-8。 函数php_sapi_name()的结果是apache2handler。

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

这是两个文件。我已经简化了一点,但通常它们没有任何问题。我有类似的GET方法文件。

<?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;
?>

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

<!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是本地服务器的名称。它的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 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>

编辑II:我可以添加更多信息。在访问日志中有例如这一行: 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“。这表明,apache2正在顺利接收帖子。但是PHP中的$ _POST仍然是完全空的。 在Firebug的显示中&gt; Net&gt;标题是内容长度0。

1 个答案:

答案 0 :(得分:1)

您的所有表单输入字段是都具有name属性还是只有id属性?它可能就像为每个输入字段添加name属性一样简单。

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

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

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