forked from xPaw/SteamID.php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VanityURLs.php
48 lines (38 loc) · 1.19 KB
/
VanityURLs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
// Simpler solution which doesn't perform any API requests and simply only works on /profiles/ urls
$SteamID = SteamID::SetFromURL( 'http://steamcommunity.com/profiles/[U:1:2]', function()
{
return null;
} );
$WebAPIKey = 'YOUR WEBAPI KEY HERE';
$SteamID = SteamID::SetFromURL( 'http://steamcommunity.com/groups/valve', function( $URL, $Type ) use ( $WebAPIKey )
{
$Parameters =
[
'format' => 'json',
'key' => $WebAPIKey,
'vanityurl' => $URL,
'url_type' => $Type
];
$c = curl_init( );
curl_setopt_array( $c, [
CURLOPT_USERAGENT => 'Steam Vanity URL Lookup',
CURLOPT_ENCODING => 'gzip',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => 'https://api.steampowered.com/ISteamUser/ResolveVanityUR/v1/?' . http_build_query( $Parameters ),
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_TIMEOUT => 5
] );
$Response = curl_exec( $c );
curl_close( $c );
$Response = json_decode( $Response, true );
if( isset( $Response[ 'response' ][ 'success' ] ) )
{
switch( (int)$Response[ 'response' ][ 'success' ] )
{
case 1: return $Response[ 'response' ][ 'steamid' ];
case 42: return null;
}
}
throw new Exception( 'Failed to perform API request' );
} );