Reputation: 302
The following code is producing the error I stated in the title:
$authkey = "XXXXXXXXXXX";
if (!isset($_SESSION["steamid"])) {
$handle = fopen("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=" . $authkey . "&steamids=" . $uid, "r");
$content = stream_get_contents($handle);
$stdclass = json_decode($content);
//var_dump($stdclass);
$data = get_object_vars($stdclass->response->players[0]);
foreach ($data as $key => $value) {
$_SESSION[$key] = $value;
}
I've read other questions here on stackoverflow with the same problem, but there never was a real solution to it. The code I posted is in an function that is called in some kind of login-process. If I put the code outside an document and open that document with my web-browser, no error comes up. Also, the code is working on my local machine. But on my server the error comes up.
My local machine runs ubuntu 12.04 with php5, my external server ubuntu 8.04 with php5. allow_url_fopen is "On". Any help would be great.
Upvotes: 1
Views: 5527
Reputation: 6730
fopen doesn't allow remote locations to be opened by default. A more stable method would be to use curl:
$c = curl_init( sprintf("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=%s&steamids=%s" , $authkey , $uid) );
curl_setopt( $c , CURLOPT_RETURNTRANSFER , true );
$stdClass = json_decode( curl_exec( $c ) );
Upvotes: 1