1

この問題を解決するのを手伝ってください。

$_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"
}
4

3 に答える 3

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
于 2013-05-10T08:52:27.983 に答える
0

投稿データが正しくエンコードされていないようです。投稿データは次の形式である必要があります

key1=value1&key2=value2&key3=value3.....

urlencode()以外のすべてが必要な場所&=

また、投稿変数を介して連想配列を送信しようとしていると思います。(たとえば jform[...]) $_POST 自体は連想配列ですが、それを介して連想配列を (何も処理せずに) 送信することはできないと思います。

于 2013-05-10T09:13:40.020 に答える