Programing

`$ HTTP_RAW_POST_DATA`가 더 이상 사용되지 않는다는 경고

lottogame 2020. 7. 17. 08:11
반응형

`$ HTTP_RAW_POST_DATA`가 더 이상 사용되지 않는다는 경고


PHP 5.6.0으로 전환했으며 이제 모든 곳에서 다음 경고가 표시됩니다.

Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will
be removed in a future version. To avoid this warning set
'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream
instead. in Unknown on line 0

Warning: Cannot modify header information - headers already sent in Unknown on line 0

좋아, 나는 더 이상 사용되지 않는 기능에 의존합니다. 내가 아닌 것을 제외하고 !

  1. 필자는 스크립트에서이 변수를 사용한 적이 없습니다. 솔직히 말해서 나는 그것이 존재하는지도 몰랐다.
  2. phpinfo()내가 always_populate_raw_post_data0으로 설정 되었음을 나타냅니다 (비활성화). 무슨 일이야?

이 값을 -1로 설정하여 "경고를 피하고 싶지 않습니다." 이것은 경고를 숨기고 구성은 더 이상 사용되지 않습니다. 소스에서 문제를 해결하고 왜 PHP가 HTTP_RAW_POST_DATA인구가 켜져 있다고 생각하는지 알고 싶습니다 .


오류 메시지에 대한 나의 이해가 잘못되었다는 것이 밝혀졌습니다. 나는 단어의 선택이 매우 좋지 않다고 말하고 싶습니다. 인터넷 검색은 다른 사람이 내가했던 것처럼 메시지를 잘못 이해했음을 보여주었습니다 . PHP 버그 # 66763을 참조하십시오 .

완전히 도움이되지 않은 후에 "이것은 RM이 원하는 방식입니다." Tyrael은 Mike의 버그에 대한 응답으로 "-1"로 설정한다고해서 경고 메시지가 사라지는 것은 아니라고 설명합니다. 그것은 올바른 일을합니다 . 즉 범인 변수 채우기를 완전히 비활성화합니다. 그것은 0으로 설정 한 것으로 나타났다는 STILL 일부 상황에서는 데이터를 채워. 나쁜 디자인에 대해 이야기하십시오! PHP RFC 를 인용하려면 :

always_populate_raw_post_data INI 설정을 2 대신 3 개의 값으로 변경하십시오.

  • -1 : 주인의 행동; $ GLOBALS를 채우지 마십시오. [HTTP_RAW_POST_DATA]
  • 0 / 꺼짐 / 무엇이든 : BC 동작 (콘텐츠 유형이 등록되지 않았거나 요청 방법이 POST 이외의 경우 채워짐)
  • 1 / on / yes / true : BC 동작 (항상 $ GLOBALS [HTTP_RAW_POST_DATA] 입력)

예, -1로 설정하면 메시지가 말한 것처럼 경고를 피할 수있을뿐만 아니라 마침내이 변수 채우기를 비활성화합니다 .


이 오류가 발생할 때까지 잠시 기다려 왔습니다. 이 문제를 우연히 발견 할 수있는 사람이라면 누구나 대답 해주십시오.

이 오류는 단지 빈 POST 요청을 보내고 있음을 의미합니다. 이 오류는 일반적으로 매개 변수가 전달되지 않은 HTTPRequest에서 발견됩니다. 이 오류를 피하기 위해 php.ini를 변경하지 않고 항상 POST에 매개 변수를 추가 할 수 있습니다.

처럼:

$.post(URL_HERE
    ,{addedvar : 'anycontent'}
    ,function(d){
       doAnyHere(d);
    }
    ,'json' //or 'html','text'
);

nginx 서버 (DigitalOcean)에서 동일한 문제가 발생했습니다. 로그인해야 root하고 파일을 수정하면됩니다 /etc/php5/fpm/php.ini.

always_populate_raw_post_data내가 처음 실행 하는 줄을 찾으려면 grep:

grep -n 'always_populate_raw_post_data' php.ini

그 줄을 반환 704

704:;always_populate_raw_post_data = -1

그런 다음 편집기를 사용 php.ini하여 해당 줄을여십시오 vi.

vi +704 php.ini

주석을 제거하고 파일을 저장하려면 세미콜론을 제거하십시오. :wq

마지막으로 서버를 재부팅하면 오류가 사라졌습니다.


WAMP 를 사용하는 경우 ...

속성 always_populate_raw_post_data추가 또는 주석 해제 php.ini하고 값을로 설정해야합니다 -1. 내 경우 php.ini에는 다음 위치에 있습니다.

C:\wamp64\bin\php\php5.6.25\php.ini

..하지만 여전히 경고 메시지가 표시되는 경우

당신은 또한 설정해야합니다 always_populate_raw_post_data = -1phpForApache.ini:

C:\wamp64\bin\php\php5.6.25\phpForApache.ini

이 파일을 찾을 수 없으면 브라우저 창을 열고 다음으로 이동하십시오.

http://localhost/?phpinfo=1

Loaded Configuration File값을 찾으십시오 . 필자의 경우 php.iniWAMP 에서 사용하는 위치는 다음과 같습니다.

C:\wamp64\bin\apache\apache2.4.23\bin\php.ini (C : \ wamp64 \ bin \ php \ php5.6.25 \ phpForApache.ini에 대한 심볼릭 링크)

마지막으로 WAMP를 다시 시작하십시오 (또는 모든 서비스 다시 시작을 클릭하십시오).


주석 해제

always_populate_raw_post_data = -1 

php.ini (line # 703)에서 APACHE 서비스를 다시 시작하면 메시지를 제거하는 데 도움이됩니다.

; Always populate the $HTTP_RAW_POST_DATA variable. PHP's default behavior is
; to disable this feature and it will be removed in a future version.
; If post reading is disabled through enable_post_data_reading,
; $HTTP_RAW_POST_DATA is *NOT* populated.
; http://php.net/always-populate-raw-post-data
; always_populate_raw_post_data = -1

.htaccess파일을 사용할 수없는 경우 루트 폴더에서이 코드 줄을지나 파일을 만듭니다.

이것을 .htaccess파일에 넣으십시오 (API에서 잘 작동하는지 테스트 됨)

<IfModule mod_php5.c>
    php_value always_populate_raw_post_data -1
</IfModule>

허용 된 답변에서 알 수 있듯이 php.init를 변경 한 후에도이 문제로 어려움을 겪고있는 사람은 누구나. POST매개 변수없이 ajax 탄원서를 작성하면 오류가 발생하므로 send 메소드를로 변경하면됩니다 GET.

var xhr = $.ajax({
   url:  url,
   type: "GET",
   dataType: "html",
   timeout: 500,
});

Still an other option if you want to keep the method POST for any reason is to add an empty JSON object to the ajax petititon.

var xhr = $.ajax({
   url:  url,
   type: "POST",
   data: {name:'emtpy_petition_data', value: 'empty'}
   dataType: "html",
   timeout: 500,
});

I got this error message when sending data from a html form (Post method). All I had to do was change the encoding in the form from "text/plain" to "application/x-www-form-urlencoded" or "multipart/form-data". The error message was very misleading.


Unfortunately, this answer here by @EatOng is not correct. After reading his answer I added a dummy variable to every AJAX request I was firing (even if some of them already had some fields) just to be sure the error never appears.

But just now I came across the same damn error from PHP. I double-confirmed that I had sent some POST data (some other fields too along with the dummy variable). PHP version 5.6.25, always_populate_raw_post_data value is set to 0.

Also, as I am sending a application/json request, PHP is not populating it to $_POST, rather I have to json_decode() the raw POST request body, accessible by php://input.

As the answer by @rr- cites,

0/off/whatever: BC behavior (populate if content-type is not registered or request method is other than POST).

Because the request method is for sure POST, I guess PHP didn't recognize/like my Content-Type: application/json request (again, why??).

OPTION 1:

Edit the php.ini file manually and set the culprit variable to -1, as many of the answers here suggest.

OPTION 2:

This is a PHP 5.6 bug. Upgrade PHP.

OPTION 3:

As @user9541305 answered here, changing the Content-Type of AJAX request to application/x-www-form-urlencoded or multipart/form-data will make PHP populate the $_POST from the POSTed body (because PHP likes/recognizes those content-type headers!?).

OPTION 4: LAST RESORT

Well, I did not want to change the Content-Type of AJAX, it would cause a lot of trouble for debugging. (Chrome DevTools nicely views the POSTed variables of JSON requests.)

I am developing this thing for a client and cannot ask them to use latest PHP, nor to edit the php.ini file. As a last resort, I will just check if it is set to 0 and if so, edit the php.ini file in my PHP script itself. Of course I will have to ask the user to restart apache. What a shame!

Here is a sample code:

<?php

if(ini_get('always_populate_raw_post_data') != '-1')
{
    // Get the path to php.ini file
    $iniFilePath = php_ini_loaded_file();

    // Get the php.ini file content
    $iniContent = file_get_contents($iniFilePath);

    // Un-comment (if commented) always_populate_raw_post_data line, and set its value to -1
    $iniContent = preg_replace('~^\s*;?\s*always_populate_raw_post_data\s*=\s*.*$~im', 'always_populate_raw_post_data = -1', $iniContent);

    // Write the content back to the php.ini file
    file_put_contents($iniFilePath, $iniContent);

    // Exit the php script here
    // Also, write some response here to notify the user and ask to restart Apache / WAMP / Whatever.
    exit;
}

Well, if there's anyone out there on a shared hosting and with no access to php.ini file, you can set this line of code at the very top of your PHP files:

ini_set('always_populate_raw_post_data', -1);

Works more of the same. I hope it saves someone some debugging time :)


; always_populate_raw_post_data = -1 in php.init remove comment of this line .. always_populate_raw_post_data = -1

참고URL : https://stackoverflow.com/questions/26261001/warning-about-http-raw-post-data-being-deprecated

반응형