2013-04-03 64 views
0

已解決:我省略了輸入字段的名稱屬性。 我有一個簡單的HTML/PHP的形式。我提交它。 $ _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。

這裏有兩個文件。我簡化了他們一些,但通常他們工作沒有任何問題。我有類似的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 [email protected] 
    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/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顯示內容長度爲0.

+1

你的表單字段的值沒有名字,因此沒有爲POST –

回答

1

是否所有的表單輸入字段都有名稱屬性或只是一個id屬性?這可能就像爲每個輸入字段添加名稱屬性一樣簡單。

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

是不一樣的

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

$ _ POST [「更遠」]應該只與第二個例子返回上述

+0

哇,確實很簡單!非常感謝,完全錯過了一週。 –

相關問題