簡體   English   中英

file_get_contents('php://input') 對一個用戶返回空,但對其他用戶工作正常

[英]file_get_contents('php://input') Returns empty for one user, but works fine for others

我的網絡服務器有一個非常奇怪的問題。 我的服務器為 file_get_contents('php://input') 顯示一個空字符串,但只有一個用戶。 它對我和其他一些人來說很好用,但是一個特定的用戶不能在使用 POST 請求的站點上使用任何東西,因為服務器只是在他的 PC 上沒有從他的瀏覽器接收到任何 POST 信息。 然而,它在他的手機上也能正常工作。 測試更加困難,因為我無法自己復制它,它對我來說效果很好。 我讓他嘗試了多種不同的瀏覽器並隱身,以防 Chrome 中有一些奇怪的設置破壞了他,但似乎沒有任何效果。 我已經檢查了他的 chrome 工具中的標題,似乎所有信息都在那里,但服務器仍然什么也沒看到。 我使用的代碼非常簡單,只需使用 fetch 發送 post 請求

 let fetchCheckoutID = fetch("stripe/createcustomcheckout.php", {
  credentials: 'include',
  method: "POST",
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    currency: customCheckoutCurrency.value.toLowerCase(),
    price: customCheckoutValue.value,
    name: customCheckoutName.value
  })
}).then(function (response) {
  return response.json();
}).then(async function (session) {
  stripe.redirectToCheckout({ sessionId: session.id});
}).then(function (result) {

  if(result.error) {
    alert(result.error.message);
  }
}).catch(function (error) {
  console.error("Stripe Setup: ", error);
});

然后在服務器端

$json = file_get_contents('php://input');
$data = json_decode($json);

這只是我發現問題的代碼,整個網站上的 POST 請求都沒有專門為他工作,但對其他人來說都很好。 在過去的 4 個小時里,我一直在和他一起試圖解決這個問題,因為幾個月來它一直在為他工作,現在突然間他基本上無法使用該站點,因為它依賴於對服務器的 POST 請求。 如果這是他可以解決的問題,那么其他用戶肯定會遇到同樣的問題......我不知道還能去哪里,我找不到任何其他有同樣問題的帖子。 我只是發現很多人在 $_POST 中找不到信息,人們建議他們使用 file_get_input() 就像已經在使用一樣。 無論如何,我已經嘗試了很多人們推薦的修復程序,即使問題並不完全相同,但到目前為止沒有任何效果。

這是他瀏覽器中的一些信息,其中一些信息已被審查。

他的請求標頭:

Request URL: ///stripe/createcustomcheckout.php
Request Method: POST
Status Code: 200 
Remote Address: ///
Referrer Policy: strict-origin-when-cross-origin
content-encoding: br
content-type: text/html; charset=UTF-8
date: Tue, 20 Jul 2021 22:17:42 GMT
host-header: 8441280b0c35cbc114
server: nginx
vary: Accept-Encoding
x-httpd: 1
x-proxy-cache-info: DT:1
:authority: ///
:method: POST
:path: /stripe/createcustomcheckout.php
:scheme: https
accept: /
accept-encoding: gzip, deflate, br
accept-language: en-US,en;q=0.9
content-length: 49
content-type: application/json
cookie: stripe_mid=499cb16f-aea1-4724-b6f7-ef968c5733696ba34;                 
stripe_sid=f2bbde34-9dab-4f3f-9dfc-bb2904e813a1716c2
origin: ///.com/
referer: ///createstripe
sec-ch-ua: " Not;A Brand";v="99", "Google Chrome";v="91",                 
"Chromium";v="91"
sec-ch-ua-mobile: ?0
sec-fetch-dest: empty
sec-fetch-mode: cors
sec-fetch-site: same-origin
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64)     
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 
Safari/537.36
{currency: "usd", price: "21", name: "ertrgdfg"}
currency: "usd"
name: "ertrgdfg"
price: "21"

這是服務器響應,我有它 var_dumping 整個 $_SERVER,底部的空字符串是早期 $json 變量的 var_dump(空 php://input)。

["PATH"]=>
string(28) "/usr/local/bin:/usr/bin:/bin"
["DOCUMENT_ROOT"]=>
string(52) "///.com/public_html"
["HTTPS"]=>
string(2) "on"
["UNIQUE_ID"]=>
string(27) "YPdK0LJppGoU///AAAAw"
["SCRIPT_URL"]=>
string(36) "/stripe/createcustomcheckout.php"
["SCRIPT_URI"]=>
string(57) "///stripe/createcustomcheckout.php"
["PHPHANDLER"]=>
string(24) "/usr/local/php74/bin/php"
["HTTP_X_PORT"]=>
string(4) "1033"
["HTTP_X_REAL_IP"]=>
string(14) "///"
["HTTP_X_FORWARDED_PROTO"]=>
string(5) "https"
["HTTP_HOST"]=>
string(13) "///.com"
["HTTP_X_ACCEPT_ENCODING"]=>
string(17) "gzip, deflate, br"
["HTTP_CONNECTION"]=>
string(5) "close"
["HTTP_SEC_CH_UA"]=>
string(64) "" Not;A Brand";v="99", "Google Chrome";v="91", 
"Chromium";v="91""
["HTTP_SEC_CH_UA_MOBILE"]=>
string(2) "?0"
["HTTP_USER_AGENT"]=>
string(115) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) 
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 
Safari/537.36"
["CONTENT_TYPE"]=>
string(16) "application/json"
["HTTP_ACCEPT"]=>
string(3) "*/*"
["HTTP_ORIGIN"]=>
string(21) "///.com"
["HTTP_SEC_FETCH_SITE"]=>
string(11) "same-origin"
["HTTP_SEC_FETCH_MODE"]=>
string(4) "cors"
["HTTP_SEC_FETCH_DEST"]=>
string(5) "empty"
["HTTP_REFERER"]=>
string(38) "///createstripe"
["HTTP_ACCEPT_LANGUAGE"]=>
string(14) "en-US,en;q=0.9"
["HTTP_COOKIE"]=>
string(112) "__stripe_mid=499cb16f-aea1-4724-b6f7-ef933696ba34; 
__stripe_sid=f2bbde34-9dab-4f3f-9dfc-bb23a1716c2"
["SERVER_SOFTWARE"]=>
string(6) "Apache"
["SERVER_NAME"]=>
string(13) "///.com"
["SERVER_ADDR"]=>
string(14) "///"
["SERVER_PORT"]=>
string(3) "443"
["REMOTE_ADDR"]=>
string(14) "///"
["SERVER_ADMIN"]=>
string(9) "webmaster"
["SCRIPT_FILENAME"]=>
string(88) "///stripe/createcustomcheckout.php"
["REMOTE_PORT"]=>
string(5) "37988"
["GATEWAY_INTERFACE"]=>
string(7) "CGI/1.1"
["SERVER_PROTOCOL"]=>
string(8) "HTTP/1.0"
["REQUEST_METHOD"]=>
string(4) "POST"
["QUERY_STRING"]=>
string(0) ""
["REQUEST_URI"]=>
string(36) "/stripe/createcustomcheckout.php"
["SCRIPT_NAME"]=>
string(36) "/stripe/createcustomcheckout.php"
["PHP_DEFAULT_SOCKET_TIMEOUT"]=>
string(2) "40"
["PHP_MAX_EXECUTION_TIME"]=>
string(3) "120"
["PHP_MAX_INPUT_TIME"]=>
string(3) "120"
["PHP_MEMORY_LIMIT"]=>
string(4) "768M"
["PHP_POST_MAX_SIZE"]=>
string(4) "256M"
["PHP_UPLOAD_MAX_FILESIZE"]=>
string(4) "256M"
["PHP_SELF"]=>
string(36) "/stripe/createcustomcheckout.php"
["REQUEST_TIME_FLOAT"]=>
float(1626819280.5109)
["REQUEST_TIME"]=>
int(1626819280) 
}
string(0) ""

我注意到來自他的請求的 $_SERVER 響應缺少 ["CONTENT-LENGTH"] 變量,而我的響應具有該變量。 然而,他在瀏覽器中的請求頭確實有一個內容長度,內容就在那里,但服務器仍然看不到任何東西。 我真的被困在這里,無法弄清楚為什么服務器沒有收到他的 POST 內容。 這不是隨機用戶,而是站點的所有者(我只是開發人員),他能夠使用它非常重要。 任何幫助將不勝感激。

好的,所以我想出了這個問題,以防將來有人遇到這個問題。 我今天花了更多時間嘗試修復這個問題,但用戶收到了一個新錯誤,這次是來自我的托管服務的整個錯誤頁面響應,超出了我的控制范圍。 這個錯誤說:

“由於安全規則,您嘗試訪問的頁面受到限制。如果您認為此安全規則影響了您網站的正常運行,請與您的托管服務提供商聯系,詳細說明如何重新創建此錯誤。”

我使用 Siteground 來托管我的網站,因此我聯系了他們以嘗試解決此問題。 長話短說,他們的后端有一個特定的安全規則,Bitdefender 存在問題,現在它阻止了他。 支持代理不得不解鎖他的 IP,他卸載了 Bitdefender,現在一切正常。 Bitdefender 出於某種原因阻止了他的 POST 請求。 我真的不明白為什么,我與之交談的支持代理無法告訴我原因,但只是嘗試卸載/禁用您的 Bitdefender,如果您被安全規則阻止,請聯系您的托管服務提供商,看看他們是否已經封鎖了IP。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM