· 6 years ago · Oct 30, 2019, 11:50 PM
1$cacheFile = "/cache/users/controller.php?id=$WHO";
2$cachetime = 60;
3
4if (file_exists($cacheFile) && time() - $cacheFile < filemtime($cacheFile)) {
5 readfile($cacheFile);
6 } else {
7 GetApiInfo($WHO);
8
9 }
10function GetApiInfo($WHO) {
11 $s = SteamID::SetFromURL( $WHO, function( $URL, $Type ) use ( $APIKEY )
12 {
13 $Parameters =
14 [
15 'format' => 'json',
16 'key' => $APIKEY,
17 'vanityurl' => $URL,
18 'url_type' => $Type
19 ];
20
21 $c = curl_init( );
22
23 curl_setopt_array( $c, [
24 CURLOPT_USERAGENT => 'Steam Vanity URL Lookup',
25 CURLOPT_ENCODING => 'gzip',
26 CURLOPT_RETURNTRANSFER => true,
27 CURLOPT_URL => 'https://api.steampowered.com/ISteamUser/ResolveVanityURL/v1/?' . http_build_query( $Parameters ),
28 CURLOPT_CONNECTTIMEOUT => 5,
29 CURLOPT_TIMEOUT => 5
30 ] );
31
32 $Response = curl_exec( $c );
33
34 curl_close( $c );
35
36 $Response = json_decode( $Response, true );
37
38 if( isset( $Response[ 'response' ][ 'success' ] ) )
39 {
40 switch( (int)$Response[ 'response' ][ 'success' ] )
41 {
42 case 1: return $Response[ 'response' ][ 'steamid' ];
43 case 42: header("Location: steamerror.php");
44
45 }
46 }
47 throw new Exception( 'Failed to perform API request' );
48
49 } );
50$id3 = $s->RenderSteam3() . PHP_EOL;
51$idn = $s->RenderSteam2() . PHP_EOL;
52$id64 = $s->ConvertToUInt64() . PHP_EOL;
53$json = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".$APIKEY."&steamids=$id64");
54$apidata = json_decode($json);
55$name = $apidata->response->players[0]->personaname;
56$img = $apidata->response->players[0]->avatarfull;
57if (isset($apidata->response->players[0]->realname) == false ){
58 $realname = "N/A";
59} else{
60 $realname = $apidata->response->players[0]->realname;
61}
62
63if (isset($apidata->response->players[0]->loccountrycode) == false ){
64 $country = "N/A";
65} else{
66 $country = $apidata->response->players[0]->loccountrycode;
67}
68$url = $apidata->response->players[0]->profileurl;
69if ($name == null || $img == null ){
70 header("Location: steamerror.php");
71}
72}