沃梦达 / 编程问答 / php问题 / 正文

$_POST, $_GET 和 $_REQUEST 为空

$_POST, $_GET and $_REQUEST Empty($_POST, $_GET 和 $_REQUEST 为空)

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

问题描述

已解决:我省略了输入字段中的名称属性.我有一个简单的 html/php -form.我提交了.$_POST 始终为空.如果我尝试获取,则 GET 始终为空.$_REQUEST 和 php://input 也是如此.我什么也得不到.

有很多关于这个主题的帖子,但我还没有找到解决我的问题的方法.我没有重写或重定向.method_request 是 POST.与表单中的 id 没有冲突,php://input 也是空的,REQUEST 也是空的.我已经把 Suhosin.simulation 设置为 on,这意味着它不起作用.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 - 补丁 0.9.1.操作系统 = Ubuntu 12.04 LTS,Apache = 2.2.22.

这里有两个文件.我对它们进行了一些简化,但通常它们可以正常工作.我有 GET 方法的类似文件.


";$tmpHeader .= "<meta charset="UTF-8"> <meta http-equiv="Content-Type" content="application/x-www-form-urlencoded;字符集=utf-8">
";$tmpHeader.= "testPost
";$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 = "
";$tmpBody .= "

";$tmpBody .= "<form id="pagewrap" name="pagewrap" method="POST" action="http://www.thuis.lb/testPost_2.php" enctype="application/x-www-form-urlencoded"> ";$tmpBody .= "<input type="hidden" id="context_id" value="testPost"> ";$tmpBody.=" ";$pageData = "
";$pageData.= "
testPost ";$pageData.= "<div class="fourcolumns_odd"><label for="username">username</label></div> ";$pageData.= "<div class="fourcolumns_even"><input type="text" id="username" value=""></div> ";$pageData.= "<div class="fourcolumns_odd"><label for="password">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.= "
";$pageData.= "<input type="hidden" id="passwordHash" value=""> ";$pageData.="</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.= "

";$tmpBody.="</section><!-- 页尾--> ";$tmpBody.="</body></html> ";logStatement('请求头:');$testpostdata = file_get_contents("php://input");log_r($testpostdata);打印 $tmpHeader.$tmpBody;?>

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

<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="容器"><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>专用于><?php print getValue('username','nothing found');?></跨度></div></标题><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">请求方法</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><!--doc_content 部分结束-->

<div id="rightWing"><img src="/images/IronPillarDelphi.jpg" alt="homerus"></div></表单></div><!-- 容器结束--></section><!-- 页面结束--></body></html>

www.thuis.lb 是本地服务器的名称.它的 IP 为 127.0.0.1.Thuis 是荷兰语,意思是在家.有什么我忘记了或者我做错了什么吗?

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

服务器名称 www.thuis.lb服务器别名 thuis.lb *.thuis.lb服务器管理员 lbergman@loekbergman.nlDocumentRoot/var/www/thuis重写引擎开启RewriteOptions 继承<目录/var/www/thuis/>选项索引 FollowSymLinks MultiViews允许覆盖所有命令允许,拒绝允许所有人</目录>脚本别名/cgi-bin//usr/lib/cgi-bin/<目录/usr/lib/cgi-bin">允许覆盖无选项 +ExecCGI -MultiViews +SymLinksIfOwnerMatch命令允许,拒绝所有人都允许</目录>ErrorLog/var/log/apache2/thuis/error.log# 可能的值包括:调试、信息、通知、警告、错误、暴击、# 警报,紧急.日志级别调试CustomLog/var/log/apache2/thuis/access.log 合并别名/doc/"/usr/share/doc/"<目录/usr/share/doc/">选项索引多视图 FollowSymLinks允许覆盖无订单拒绝,允许拒绝所有人允许来自 127.0.0.0/255.0.0.0 ::1/128</目录></虚拟主机>

编辑二:我可以添加更多信息.例如,在访问日志中有这一行: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>Net>Headers 的显示中是 Content Length 0.

解决方案

您的所有表单输入字段都具有名称属性还是仅具有 id 属性?可能就像为每个输入字段添加名称属性一样简单.

不一样

$_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>
";
$tmpHeader .= "<meta charset="UTF-8"> <meta http-equiv="Content-Type" content="application/x-www-form-urlencoded; charset=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.php" enctype="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><legend>testPost</legend>
";
$pageData.= "<div class="fourcolumns_odd"><label for="username">username</label></div>
";
$pageData.= "<div class="fourcolumns_even"><input type="text" id="username" value=""></div>
";
$pageData.= "<div class="fourcolumns_odd"><label for="password">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><!--end 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><!-- end of container -->
";
$tmpBody.="</section><!-- end of page -->
";
$tmpBody.="</body></html>
";

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 为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:$_POST, $_GET 和 $_REQUEST 为空

基础教程推荐

猜你喜欢