PHP file_get_contents(string)반환합니다 bool(false)때에 동일한 문자열 결과를 반환합니다 브라우저

0

질문

일부된 코드 작업에 대한 개월이 갑자기 작동하지 않습니다. 나이로 좁혀 PHP file_get_contents 부분입니다. 여기에는 싹둑의 코드:

// This upper portion was added to send a user-agent with the request
$opts = [
    "http" => [
        "method" => "GET",
        "header" => "Accept-language: en\r\n" .
        "User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n",
    ],
];
$context = stream_context_create($opts);
// End of the added part except for the actual get-file-contents request line


$ViewLat = 40.7;
$ViewLng = -73.9;
$Distance = 1000;
$input1 = "https://api.helium.io/v1/hotspots/location/distance?lat=40.7&lon=-73.9&distance=1000";
$input2 = "https://api.helium.io/v1/hotspots/location/distance/?lat=$ViewLat&lon=$ViewLng&distance=$Distance";
$json_string = file_get_contents(urlencode($input2), false, $context); // added the last 2 arguments

var_dump($ViewLat);
echo "<br>";
var_dump($ViewLng);
echo "<br>";
var_dump($Distance);
echo "<br>";
var_dump($input1);
echo "<br>";
var_dump($json_string);

그것이 문제가되지 않은 경우 사용$input1 또는$input2,그들은 둘 다 반환 bool(false)를 위해서 var_dump 를 ouput. 하지만 경우에 당신을 넣어 문자열을 직접 브라우저로,그것은 배열을 반환합니다.

이 코드는 작업에 다시장/하지만 지금은 하지 않습니다.

기 위해서 var_dump 를 출력:

float(40.7)
float(-73.9)
int(1000)
string(84) "https://api.helium.io/v1/hotspots/location/distance?lat=40.7&lon=-73.9&distance=1000"
bool(false)
api file-get-contents php
2021-11-23 19:13:04
1

최고의 응답

0

성공!!!! 했다 추가하는 일부 사용자 에이전트한 정보를 파일에 얻 내용을 요청합니다. 나는 것입 업데이트는 위의 코드를 추가했다.

2021-11-23 20:48:16

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................