• Garry's Mod Loading Screen
    18 replies, posted
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.
[CODE] <?php error_reporting(1); @set_time_limit(3); $r = mt_rand(1,3); $plname = ''; $map = ''; $avatar = 'img/nouser.png'; $authors = array( 1 => 'Metal Gear Solid OST - Encounter', 2 => 'FTL OST - Miky Way Battle', 3 => 'FTL OST - Milky Way Battle' ); $pictures = array(1,2,3); shuffle($pictures); if (isset($_GET['mapname'])) $map = '<br>Loading: '.$_GET['mapname']; if (isset($_GET['steamid'])) { $data = 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=XXXXXXXXXXXXXXXXXXXXXXXXXX&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']; } ?> <!DOCTYPE html> <html class="no-js"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title></title> <meta name="description" content=""> <meta name="viewport" content="width=device-width"> <link rel="stylesheet" href="css/bootstrap.min.css"> <link rel="stylesheet" href="css/main.css"> <link rel="stylesheet" href="css/animations.css"> <script src="js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script> </head> <body> <audio autoplay loop> <source src="music/<?php echo $r?>.ogg" type="audio/ogg"> </audio> <div class="container"> <div class="jumbotron" style="margin-top: 50px;"> <div class="pull-right cycle-slideshow" data-cycle-fx="none"> <?php foreach ($pictures as $pic) { echo '<img src="img/'.$pic.'.jpg" alt="Picture '.$pic.'" class="imgtop img-rounded">'; }?> </div> <h1 id="title" class="bigEntrance" style="font-size: 50px;">Nologam Garry's Mod Server</h1> <p class="lead"> Welcome to server. Have fun!<br> <small> <ul style="line-height: 1.6;"> <li>Be friendly.</li> <li>No random killing - low karma autoban enabled.</li> <li>No Ghosting!</li> <li>Active Admin staff</li> </ul> <br> Visit our forums at </small> <br> http://nologam.com </p> </div> </div> <div style="position: absolute;bottom: 0px;left: 20px;font-size: 12px;min-width: 260px;" class="well well-sm"> <img src="<?php echo $avatar ?>" alt="" class="pull-right img-circle"> Hello, <b><?php echo $plname ?></b><?php echo $map ?><br> Music: "<?php echo $authors[$r];?>" </div> <script src="js/vendor/jquery-1.10.1.min.js"></script> <script src="js/vendor/bootstrap.min.js"></script> <script src="js/jquery.cycle2.min.js"></script> <script src="js/main.js"></script> </body> </html> [/CODE]
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&amp;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.