Hi,
I'm currently setting up a custom loading screen for my gmod server, my progress thus far can be seen here: [url]http://download.reidweb.com/gmodloadingscreen/?steamid=76561198048471913&mapname=test[/url]
I'm using the following code to try and get the "personaname" of the player; however it returns nothing - the name should be displayed after the "hello" in bottom left.
[CODE]
if (isset($_GET['steamid'])) {
$data = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&steamids='.$_GET['steamid'];
$f = file_get_contents($data);
$arr = json_decode($f, true);
if (isset($arr['response']['players'][0]['personaname']))
$plname = $arr['response']['players'][0]['personaname'];
if (isset($arr['response']['players'][0]['avatar']))
$avatar = $arr['response']['players'][0]['avatar'];
}
[/CODE]
EDIT: Corrected Code
you're trying to decode data from $f, but that variable doesn't exist. Did you mean json_decode($[I]fdata[/I],true); ?
[QUOTE=Coment;45864018]you're trying to decode data from $f, but that variable doesn't exist. Did you mean json_decode($[I]fdata[/I],true); ?[/QUOTE]
Ah yeah; i did notice that and did correct it in my code; forgot to update here though. Still no fixed :(
Why not post the entire (updated) script so we can give it a look?
Also, if I were you I'd remove your steam API key from there. Those things are usually secret.
Oh, and do var_dump($f); somewhere after that file_get_contents. Wild guess is that your hosting has disabled it and it's just not returning anything.
[QUOTE=Coment;45864088]Oh, and do var_dump($f); somewhere after that file_get_contents. Wild guess is that your hosting has disabled it and it's just not returning anything.[/QUOTE]
Done. Returns "bool(false)" for some reason
[QUOTE]bool(false) [/QUOTE]
There we go. Just as I thought, your hosting has disabled file_get_contents for external files.
Replace that file_get_contents by
[code]
function curl_download($Url){
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
$data = curl_download(<insert that long url here>);
[/code]
[QUOTE=Coment;45864154]There we go. Just as I thought, your hosting has disabled file_get_contents for external files.
Replace that file_get_contents by
[code]
function curl_download($Url){
if (!function_exists('curl_init')){
die('Sorry cURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
$data = curl_download(<insert that long url here>);
[/code][/QUOTE]
Oh; I can enable that - it is a dedicated server, I mainly program in Java and bash; haven't dabbled much in PHP so am just running stock config.
Which config do i edit that in?
[editline]1st September 2014[/editline]
From my php.ini
; Whether to allow the treatment of URLs (like http:// or [url]ftp://)[/url] as files.
; [url]http://php.net/allow-url-fopen[/url]
allow_url_fopen = On
; Whether to allow include/require to open URLs (like http:// or [url]ftp://)[/url] as files.
; [url]http://php.net/allow-url-include[/url]
allow_url_include = On
...That's weird then, it comes activated by default. Could you set error_reporting(E_ALL) ? I fear that it might be blocking some error, because I checked the api link and it seems fine.
[QUOTE=Coment;45864336]...That's weird then, it comes activated by default. Could you set error_reporting(E_ALL) ? I fear that it might be blocking some error, because I checked the api link and it seems fine.[/QUOTE]
Done; where does it log to?
[editline]1st September 2014[/editline]
from my nginx error log:
PHP message: PHP Warning: file_get_contents([url]http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=E161DCA8360B61711DCC4FB2D174A38E&steamids=76561198053256252):[/url] failed to open stream: php_network_getaddresses: getaddr$
--From what I'm reading on SO, it's a problem with the server not reaching a DNS. Not sure where to go from there, if I'm honest. I hope someone else can help you with this.
My dedi's DNS is definitely configured correctly; i've been running for months and not had any issue like this.
[editline]1st September 2014[/editline]
[QUOTE=Coment;45864476]--From what I'm reading on SO, it's a problem with the server not reaching a DNS. Not sure where to go from there, if I'm honest. I hope someone else can help you with this.[/QUOTE]
Thanks for the help; I'm looking into it now; apparently steam web api was having issues earlier :/
Have a look at the URL:
[url]http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=E161DCA8360B61711DCC4FB2D174A38E&[/url][B]amp;[/B]steamids=76561198053256252
It should be:
[url]http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=E161DCA8360B61711DCC4FB2D174A38E&steamids=76561198053256252[/url]
Could you do a [B]var_dump($data);[/B] for me?
I'm guessing this:
[code]$data = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=XXXXXXXXXXXXXXXXXXXXXXXXXX&steamids='.$_GET['steamid'];[/code]
should be
[code]
$data = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=XXXXXXXXXXXXXXXXXXXXXXXXXX&steamids=" . $_GET['steamid'];
[/code]
I have a feeling those single quotes in the $_GET param is escaping the string, so try with the latest code block I posted.
[QUOTE=Svenskunganka;45865867]Have a look at the URL:
[url]http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=E161DCA8360B61711DCC4FB2D174A38E&[/url][B]amp;[/B]steamids=76561198053256252
It should be:
[url]http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=E161DCA8360B61711DCC4FB2D174A38E&steamids=76561198053256252[/url]
Could you do a [B]var_dump($data);[/B] for me?
I'm guessing this:
[code]$data = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=XXXXXXXXXXXXXXXXXXXXXXXXXX&steamids='.$_GET['steamid'];[/code]
should be
[code]
$data = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=XXXXXXXXXXXXXXXXXXXXXXXXXX&steamids=" . $_GET['steamid'];
[/code]
I have a feeling those single quotes in the $_GET param is escaping the string, so try with the latest code block I posted.[/QUOTE]
Good idea; however that didn't work :/
[QUOTE=Svenskunganka;45865867]Have a look at the URL:
[url]http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=E161DCA8360B61711DCC4FB2D174A38E&[/url][B]amp;[/B]steamids=76561198053256252
It should be:
[url]http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=E161DCA8360B61711DCC4FB2D174A38E&steamids=76561198053256252[/url]
Could you do a [B]var_dump($data);[/B] for me?
I'm guessing this:
[code]$data = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=XXXXXXXXXXXXXXXXXXXXXXXXXX&steamids='.$_GET['steamid'];[/code]
should be
[code]
$data = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=XXXXXXXXXXXXXXXXXXXXXXXXXX&steamids=" . $_GET['steamid'];
[/code]
I have a feeling those single quotes in the $_GET param is escaping the string, so try with the latest code block I posted.[/QUOTE]
FYI, spaces between strings and variables don't matter. You can do
[code]"s".$m;
"s" . $m;
"s" .
$m;[/code]
and they all do the same. People often take advantage of it for long strings, like
$lorem_ipsum = "Lorem ipsum amen something something ".
"I don't know how this keeps going like wtf ".
"who the hell would learn the lorem ipsum text ".
"it's literally made as a placeholder I mean come on";
[URL="http://viper-7.com/wJyfYz"]Check it out.[/URL]
[QUOTE=Coment;45870014]FYI, spaces between strings and variables don't matter. You can do
[code]"s".$m;
"s" . $m;
"s" .
$m;[/code]
and they all do the same. People often take advantage of it for long strings, like
$lorem_ipsum = "Lorem ipsum amen something something ".
"I don't know how this keeps going like wtf ".
"who the hell would learn the lorem ipsum text ".
"it's literally made as a placeholder I mean come on";
[URL="http://viper-7.com/wJyfYz"]Check it out.[/URL][/QUOTE]
Really? You should know that I am aware of that, I added it for readability, and it's good practice and syntax compared to [B]"text".$variable.$array['index']."text123";[/B]
[QUOTE=Svenskunganka;45870135]Really? You should know that I am aware of that, I added it for readability, and it's good practice and syntax compared to [B]"text".$variable.$array['index']."text123";[/B][/QUOTE]
Well, you didn't indicate that anywhere in your post, so both OP and I thought you meant it as a solution to his problem.
[QUOTE=Coment;45870191]Well, you didn't indicate that anywhere in your post, so both OP and I thought you meant it as a solution to his problem.[/QUOTE]
[quote]I have a feeling those single quotes in the $_GET param is escaping the string[/quote]
Sorry, you need to Log In to post a reply to this thread.