-
Notifications
You must be signed in to change notification settings - Fork 0
/
steam_utils.php
54 lines (44 loc) · 1.2 KB
/
steam_utils.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
49
50
51
52
53
54
<?php
/**
* SteamID PHP Conversion Functions
* @author Paul van der Knaap <[email protected]>
* @modified 21-4-2015
*
* LICENSE: Free to use, modify and distribute in any form.df
* Original Credits for the algoritm to voogru
* https://forums.alliedmods.net/showthread.php?t=60899?t=60899
*
* This function requires the bclib library to be bundled with PHP.
*/
/**
* Returns a steam64 id from a steamid.
* @param $steamID a steamid (STEAM_0:x:xxxxxxxx)
*/
function steamIDto64($steamID){
if(empty($steamID)){
return 0;
}
$expl = explode(':',str_replace('STEAM_','',$steamID));
if(count($expl) != 3){
return 0;
}
$iServer = intval($expl[1]);
$iAuthID = intval($expl[2]);
$steamID64 = bcadd(bcadd(bcmul($iAuthID,2),'76561197960265728'),$iServer,0);
return $steamID64;
}
/**
* Returns a steamid from a 64-bit steamid.
* @param $steam64ID a 64-bit steamid.
*/
function steam64toID($steam64ID){
if(empty($steam64ID)){
return 0;
}
$iServer = bcmod($steam64ID,2);
$steamID = bcdiv(bcsub(bcsub($steam64ID,$iServer),'76561197960265728'),2,0);
return 'STEAM_0:'.$iServer.':'.$steamID;
}
// Example
$longSteamID = steamIDto64('STEAM_0:1:123456789');
$shortSteamID = steam64toID($longSteamID);