I want to convert the long SteamID64 (76561198009474628) string into the smaller SteamID (STEAM_0:0:24604450) using PHP.
I need the short SteamID's because we've been using it on our mySQL and the sv_loadingurl only has comments which can receive the long steamid64 strings.
After a little bit of research I started creating a php script which would convert the long SteamID64 into the short one. It's almost complete there's just one thing missing because the last digit of the steamid sometimes differs by 0 - 9.
What I have now:
[PHP]
<?php
// My steamid for testing purposes
$id = "76561198009474628";
function parseInt($string) {
// return intval($string);
if(preg_match('/(\d+)/', $string, $array)) {
return $array[1];
} else {
return 0;
}}
// Convert SteamID64 into SteamID
$steamY = parseInt($id);
$steamY = $steamY - 76561197960265728;
$steamX = 0;
if ($steamY%2 == 1){
$steamX = 1;
} else {
$steamX = 0;
}
$steamY = (($steamY - $steamX) / 2);
$steamID = "STEAM:_0:" . (string)$steamX . ":" . (string)$steamY;
echo $steamID;
?>[/PHP]
As you can see the input is [B]76561198009474628 [/B]and the output results in to [B]STEAM:_0:0:24604448 [/B]while this should be [B]STEAM_0:0:24604450 [/B]which just differs by 2.
Some other results were:
[TABLE="width: 600"]
[TR]
[TD]Input[/TD]
[TD]Output[/TD]
[TD]Should be[/TD]
[/TR]
[TR]
[TD]76561197996067746[/TD]
[TD]STEAM:_0:0:17901008[/TD]
[TD]STEAM_0:0:17901009[/TD]
[/TR]
[TR]
[TD]76561198039910918[/TD]
[TD]STEAM:_0:0:39822592[/TD]
[TD]STEAM_0:0:39822595[/TD]
[/TR]
[TR]
[TD]76561198000756523[/TD]
[TD]STEAM:_0:0:20245400[/TD]
[TD]STEAM_0:1:20245397[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[/TABLE]
I know I'm really close, but there needs to be a solution.
If you guys know what I'm doing wrong, please tell me!
Just want to post that I found the problem...
With the following changes the calculation works:
[PHP]
$subid = substr($id, 4); // because calculators are fags
$steamY = parseInt($subid);
$steamY = $steamY - 1197960265728; //76561197960265728
[/PHP]
I think its because the calculation preformed was way out of bounds for a 32 bit calculator. I used a sloppy technique to fix this by using a sub string and just removing the first 4 digits.
thanks anyways!
Even though you solved your problem, take a look at the [url=http://php.net/manual/en/ref.bc.php]BC Math Functions[/url], e.g. [url=http://php.net/manual/en/function.bcadd.php]bcadd[/url]. They let you work with larger numbers (or, well, strings that represent numbers).
This function makes use of the BC Math Functions.
[CODE]
function steamid64ToSteamid($steamid64){
$offset = bcsub($steamid64, '76561197960265728');
$id = bcdiv($offset, '2');
if(bcmod($offset, '2')) {
$steamid = 'STEAM_0:1:' . bcadd($id, '2');
}else{
$steamid = "STEAM_0:0:" . bcadd($id, '1');
}
return $steamid;
}
[/CODE]
Mate...... [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexb59e.html[/url]
Google is pretty useful.
Sorry, you need to Log In to post a reply to this thread.