请帮我解决这个问题。
我想从$ _POST数组中获取数据,但它返回为空,但php:// input返回所有数据。
这是我的代码:
echo $_SERVER['CONTENT_TYPE'];
$post = file_get_contents('php://input');
print "post data: <pre>";
var_dump($post);
echo "-----------------------<br>";
var_dump($_POST);
输出:
application/x-www-form-urlencodedDATA:
string(6529) "jform%5Bsitename%5D=Test&jform%5Boffline%5D=0&jform%5Bdisplay_offline_message%5D=1&jform%5Boffline_message%5D=This+site+is+down+for+maintenance.%3Cbr+%2F%3E+Please+check+back+again+soon.&jform%5Boffline_image%5D=&jform%5Beditor%5D=tinymce&jform%5Bcaptcha%5D=0&jform%5Baccess%5D=1&jform%5Blist_limit%5D=20&jform%5Bfeed_limit%5D=10&jform%5Bfeed_email%5D=author&jform%5BMetaDesc%5D=&jform%5BMetaKeys%5D=&jform%5Brobots%5D=&jform%5BMetaRights%5D=&jform%5BMetaAuthor%5D=1&jform%5BMetaVersion%5D=0&jform%5Bsef%5D=1&jform%5Bsef_rewrite%5D=0&jform%5Bsef_suffix%5D=0&jform%5Bunicodeslugs%5D=0&jform%5Bsitename_pagetitles%5D=0&jform%5Bcookie_domain%5D=&jform%5Bcookie_path%5D=&jform%5Blog_path%5D=%2Fvar%2Fwww%2Fvhosts%2Fencros.dedibox.fr%2Fhttpdocs%2Ffresh%2Flogs&jform%5Bhelpurl%5D=http%3A%2F%2Fhelp.joomla.org%2Fproxy%2Findex.php%3Foption%3Dcom_help%26keyref%3DHelp%7Bmajor%7D%7Bminor%7D%3A%7Bkeyref%7D&jform%5Bdebug%5D=1&jform%5Bdebug_lang%5D=0&jform%5Bcaching%5D=0&jform%5Bcache_handler%5D=file&jform%5Bcachetime%5D=150000&jform%5Blifetime%5D=15000&jform%5Bsession_handler%5D=database&jform%5Btmp_path%5D=%2Fvar%2Fwww%2Fvhosts%2Fencros.dedibox.fr%2Fhttpdocs%2Ffresh%2Ftmp&jform%5Bgzip%5D=0&jform%5Berror_reporting%5D=default&jform%5Bforce_ssl%5D=0&jform%5Boffset%5D=UTC&jform%5Bftp_enable%5D=0&jform%5Bftp_host%5D=127.0.0.1&jform%5Bftp_port%5D=21&jform%5Bftp_user%5D=&jform%5Bftp_pass%5D=&jform%5Bftp_root%5D=&jform%5Bdbtype%5D=mysqli&jform%5Bhost%5D=localhost&jform%5Buser%5D=testEncrosRC&jform%5Bdb%5D=testEncros&jform%5Bdbprefix%5D=mj_&jform%5Bmailer%5D=mail&jform%5Bmailfrom%5D=sandeep.s%40raincreatives.com&jform%5Bfromname%5D=Test&jform%5Bsendmail%5D=%2Fusr%2Fsbin%2Fsendmail&jform%5Bsmtpauth%5D=0&jform%5Bsmtpsecure%5D=none&jform%5Bsmtpport%5D=25&jform%5Bsmtpuser%5D=&jform%5Bsmtppass%5D=&jform%5Bsmtphost%5D=localhost&jform%5Brules%5D%5Bcore.login.site%5D%5B1%5D=&jform%5Brules%5D%5Bcore.login.admin%5D%5B1%5D=&jform%5Brules%5D%5Bcore.login.offline%5D%5B1%5D=&jform%5Brules%5D%5Bcore.admin%5D%5B1%5D=&jform%5Brules%5D%5Bcore.manage%5D%5B1%5D=&jform%5Brules%5D%5Bcore.create%5D%5B1%5D=&jform%5Brules%5D%5Bcore.delete%5D%5B1%5D=&jform%5Brules%5D%5Bcore.edit%5D%5B1%5D=&jform%5Brules%5D%5Bcore.edit.state%5D%5B1%5D=&jform%5Brules%5D%5Bcore.edit.own%5D%5B1%5D=&jform%5Brules%5D%5Bcore.login.site%5D%5B6%5D=1&jform%5Brules%5D%5Bcore.login.admin%5D%5B6%5D=1&jform%5Brules%5D%5Bcore.login.offline%5D%5B6%5D=1&jform%5Brules%5D%5Bcore.admin%5D%5B6%5D=&jform%5Brules%5D%5Bcore.manage%5D%5B6%5D=&jform%5Brules%5D%5Bcore.create%5D%5B6%5D=1&jform%5Brules%5D%5Bcore.delete%5D%5B6%5D=1&jform%5Brules%5D%5Bcore.edit%5D%5B6%5D=1&jform%5Brules%5D%5Bcore.edit.state%5D%5B6%5D=1&jform%5Brules%5D%5Bcore.edit.own%5D%5B6%5D=1&jform%5Brules%5D%5Bcore.login.site%5D%5B7%5D=&jform%5Brules%5D%5Bcore.login.admin%5D%5B7%5D=&jform%5Brules%5D%5Bcore.login.offline%5D%5B7%5D=&jform%5Brules%5D%5Bcore.admin%5D%5B7%5D=&jform%5Brules%5D%5Bcore.manage%5D%5B7%5D=1&jform%5Brules%5D%5Bcore.create%5D%5B7%5D=&jform%5Brules%5D%5Bcore.delete%5D%5B7%5D=&jform%5Brules%5D%5Bcore.edit%5D%5B7%5D=&jform%5Brules%5D%5Bcore.edit.state%5D%5B7%5D=&jform%5Brules%5D%5Bcore.edit.own%5D%5B7%5D=&jform%5Brules%5D%5Bcore.login.site%5D%5B2%5D=1&jform%5Brules%5D%5Bcore.login.admin%5D%5B2%5D=&jform%5Brules%5D%5Bcore.login.offline%5D%5B2%5D=&jform%5Brules%5D%5Bcore.admin%5D%5B2%5D=&jform%5Brules%5D%5Bcore.manage%5D%5B2%5D=&jform%5Brules%5D%5Bcore.create%5D%5B2%5D=&jform%5Brules%5D%5Bcore.delete%5D%5B2%5D=&jform%5Brules%5D%5Bcore.edit%5D%5B2%5D=&jform%5Brules%5D%5Bcore.edit.state%5D%5B2%5D=&jform%5Brules%5D%5Bcore.edit.own%5D%5B2%5D=&jform%5Brules%5D%5Bcore.login.site%5D%5B3%5D=&jform%5Brules%5D%5Bcore.login.admin%5D%5B3%5D=&jform%5Brules%5D%5Bcore.login.offline%5D%5B3%5D=&jform%5Brules%5D%5Bcore.admin%5D%5B3%5D=&jform%5Brules%5D%5Bcore.manage%5D%5B3%5D=&jform%5Brules%5D%5Bcore.create%5D%5B3%5D=1&jform%5Brules%5D%5Bcore.delete%5D%5B3%5D=&jform%5Brules%5D%5Bcore.edit%5D%5B3%5D=&jform%5Brules%5D%5Bcore.edit.state%5D%5B3%5D=&jform%5Brules%5D%5Bcore.edit.own%5D%5B3%5D=1&jform%5Brules%5D%5Bcore.login.site%5D%5B4%5D=&jform%5Brules%5D%5Bcore.login.admin%5D%5B4%5D=&jform%5Brules%5D%5Bcore.login.offline%5D%5B4%5D=&jform%5Brules%5D%5Bcore.admin%5D%5B4%5D=&jform%5Brules%5D%5Bcore.manage%5D%5B4%5D=&jform%5Brules%5D%5Bcore.create%5D%5B4%5D=&jform%5Brules%5D%5Bcore.delete%5D%5B4%5D=&jform%5Brules%5D%5Bcore.edit%5D%5B4%5D=1&jform%5Brules%5D%5Bcore.edit.state%5D%5B4%5D=&jform%5Brules%5D%5Bcore.edit.own%5D%5B4%5D=&jform%5Brules%5D%5Bcore.login.site%5D%5B5%5D=&jform%5Brules%5D%5Bcore.login.admin%5D%5B5%5D=&jform%5Brules%5D%5Bcore.login.offline%5D%5B5%5D=&jform%5Brules%5D%5Bcore.admin%5D%5B5%5D=&jform%5Brules%5D%5Bcore.manage%5D%5B5%5D=&jform%5Brules%5D%5Bcore.create%5D%5B5%5D=&jform%5Brules%5D%5Bcore.delete%5D%5B5%5D=&jform%5Brules%5D%5Bcore.edit%5D%5B5%5D=&jform%5Brules%5D%5Bcore.edit.state%5D%5B5%5D=1&jform%5Brules%5D%5Bcore.edit.own%5D%5B5%5D=&jform%5Brules%5D%5Bcore.login.site%5D%5B8%5D=&jform%5Brules%5D%5Bcore.login.admin%5D%5B8%5D=&jform%5Brules%5D%5Bcore.login.offline%5D%5B8%5D=&jform%5Brules%5D%5Bcore.admin%5D%5B8%5D=1&jform%5Brules%5D%5Bcore.manage%5D%5B8%5D=&jform%5Brules%5D%5Bcore.create%5D%5B8%5D=&jform%5Brules%5D%5Bcore.delete%5D%5B8%5D=&jform%5Brules%5D%5Bcore.edit%5D%5B8%5D=&jform%5Brules%5D%5Bcore.edit.state%5D%5B8%5D=&jform%5Brules%5D%5Bcore.edit.own%5D%5B8%5D=&jform%5Bfilters%5D%5B1%5D%5Bfilter_type%5D=NH&jform%5Bfilters%5D%5B1%5D%5Bfilter_tags%5D=&jform%5Bfilters%5D%5B1%5D%5Bfilter_attributes%5D=&jform%5Bfilters%5D%5B6%5D%5Bfilter_type%5D=BL&jform%5Bfilters%5D%5B6%5D%5Bfilter_tags%5D=&jform%5Bfilters%5D%5B6%5D%5Bfilter_attributes%5D=&jform%5Bfilters%5D%5B7%5D%5Bfilter_type%5D=NONE&jform%5Bfilters%5D%5B7%5D%5Bfilter_tags%5D=&jform%5Bfilters%5D%5B7%5D%5Bfilter_attributes%5D=&jform%5Bfilters%5D%5B2%5D%5Bfilter_type%5D=NH&jform%5Bfilters%5D%5B2%5D%5Bfilter_tags%5D=&jform%5Bfilters%5D%5B2%5D%5Bfilter_attributes%5D=&jform%5Bfilters%5D%5B3%5D%5Bfilter_type%5D=BL&jform%5Bfilters%5D%5B3%5D%5Bfilter_tags%5D=&jform%5Bfilters%5D%5B3%5D%5Bfilter_attributes%5D=&jform%5Bfilters%5D%5B4%5D%5Bfilter_type%5D=BL&jform%5Bfilters%5D%5B4%5D%5Bfilter_tags%5D=&jform%5Bfilters%5D%5B4%5D%5Bfilter_attributes%5D=&jform%5Bfilters%5D%5B5%5D%5Bfilter_type%5D=BL&jform%5Bfilters%5D%5B5%5D%5Bfilter_tags%5D=&jform%5Bfilters%5D%5B5%5D%5Bfilter_attributes%5D=&jform%5Bfilters%5D%5B8%5D%5Bfilter_type%5D=NONE&jform%5Bfilters%5D%5B8%5D%5Bfilter_tags%5D=&jform%5Bfilters%5D%5B8%5D%5Bfilter_attributes%5D=&task=application.apply&9df64a24b7288428c3919d02fb00848e=1"
-----------------------
array(4) {
["jform"]=>
string(18) "/usr/sbin/sendmail"
["task"]=>
string(5) "apply"
["9df64a24b7288428c3919d02fb00848e"]=>
string(1) "1"
["option"]=>
string(10) "com_config"
}
答案 0 :(得分:1)
您是否尝试打印$ _POST进行图片文件上传,那么您错了就应该使用$ _FILES
var_dump($_FILES);
答案 1 :(得分:0)
更新:我已经使用您的帖子正文进行了一些测试。无法重现您的问题。
解决方法:使用函数parse_str($post);
:
parse_str($post, $array);
var_dump($array);
输出:
array(3) {
'jform' =>
array(61) {
'sitename' =>
string(4) "Test"
'offline' =>
string(1) "0"
'display_offline_message' =>
string(1) "1"
'offline_message' =>
string(70) "This site is down for maintenance.<br /> Please check back again soon."
'offline_image' =>
string(0) ""
'editor' =>
string(7) "tinymce"
'captcha' =>
string(1) "0"
'access' =>
string(1) "1"
'list_limit' =>
string(2) "20"
'feed_limit' =>
... // many will follow
答案 2 :(得分:0)
您的帖子数据似乎无法正确编码。帖子数据应采用
的形式key1=value1&key2=value2&key3=value3.....
您需要urlencode()
除&
和=
我也认为你试图通过post vars发送一个关联数组。 (例如jform [...])虽然$ _POST本身就是一个关联数组,但我认为不可能通过它发送关联数组(没有任何处理)