Mitchell Welch Mitchell Welch - 3 months ago 14
PHP Question

file_get_contents failed to open stream : invalid argument with URL

I am trying to get details for bans on a Steam user account using the file_get_contents function in PHP. However, it keeps erroring and I have no idea why:

$detailURL = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=3C11B751BB59DEEE28D744C0A8BAC2EC&steamids=76561198078737264");
$profile = file_get_contents($detailURL);
$buffer = fopen("coOn4LxnQm/{$steamIDpost}.json", "w+");
fwrite($buffer, $profile);
fclose($buffer);

$steam = json_decode(file_get_contents("coOn4LxnQm/{$steamIDpost}.json"));


The error is as follows:

Warning: file_get_contents({ "players": [ { "SteamId": "76561198078737264", "CommunityBanned": false, "VACBanned": true, "NumberOfVACBans": 1, "DaysSinceLastBan": 309, "NumberOfGameBans": 0, "EconomyBan": "none" } ] }): failed to open stream: Invalid argument in C:\xampp\htdocs\addToList.php on line 18


If you have any idea, please help me. No idea what "failed to open stream: Invalid argument" means and googling and such did not help much.

Thanks.

Answer

After this line

$detailURL = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=3C11B751BB59DEEE28D744C0A8BAC2EC&steamids=76561198078737264");

$detailURL will now contain the result from the API (a JSON String)

If you have a look at this line:

$profile = file_get_contents($detailURL);

This line is doing a file_get_contents on a JSON String, and it has no sense.