-->

$ _ POST,$ _GET和$ _REQUEST空($_POST, $_GET and $_RE

2019-08-19 04:32发布

解决 :我省略了输入字段的名称属性。 我有一个简单的HTML / PHP的构型中。 我提交。 该$ _ POST始终是空的。 如果我尝试获取,则GET始终是空的。 同为$ _REQUEST和php://输入。 我得到什么回报。

还有很多与此主题的帖子,但我还没有找到我的问题的解决方案。 我没有重写或重定向。 该method_request是POST。 没有与ID的形式,PHP没有冲突://输入为空为好,要求是空的为好。 我已经把Suhosin.simulation上,这意味着它不能正常工作。 的post_max_size = 16M。 应该足以使两个小文本。

在php.ini变量request_order和variable_order分别是GP和GPS。 magic_quotes_gpc被关闭。 默认的MIME类型= text / html的和每一个页面字符集UTF-8。 函数php_sapi_name()的结果是apache2handler。

PHPVersion = 5.3,了Suhosin - 补丁0.9.1。 OS = Ubuntu的LTS 12.04,阿帕奇= 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>

编辑二:我可以添加更多的信息。 在访问日志中有例如这一行:127.0.0.1 - - [04 /月/ 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)壁虎/ 20100101火狐/ 19.0“。 这表明该伊莫Apache2的是receving在良好的秩序后。 但在PHP中的$ _ POST仍然完全是空的。 在萤火虫>网的显示>集管是内容长度0。

Answer 1:

是不是所有的表单输入域有一个name属性或只是一个ID属性? 这可能是因为添加name属性每个输入字段一样简单。

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

是不一样的

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

$ _POST [“更远”]应该只与第二示例返回以上的值



文章来源: $_POST, $_GET and $_REQUEST Empty