1

So I am working in PHP to convert a Steam Id, which many of you may be familiar with. I have the following steam ID:

STEAM_0:1:1514332

Now, I need to convert this to the 64 bit version, which is also the community ID. After browsing Steams official release on this here: http://developer.valvesoftware.com/wiki/SteamID and after also looking many places online, I have found the following method works for this:

Let X,Y, and Z be defined by the Steam ID: STEAM_X:Y:Z
SteamCommunityID = (Z*2) + 76561197960265728 + Y

So it works! However, where seems to be a mismatch between my ACTUAL community ID, and the one I am generating

Actual:        76561197963294393
PHP generated: 76561197963294000

When reversing the equasion, to get my steam id from the community id, I get: 1514335.5

Here is a simple example of the php in question:

//STEAM_0:1:1514332

$a = (1514332 * 2) + 76561197960265728 + 1;
echo $a; //76561197963294000

Am I doing something wrong?

J-16 SDiZ
  • 26,473
  • 4
  • 65
  • 84
grep
  • 3,986
  • 7
  • 45
  • 67

8 Answers8

3

Personally, I use the following code and it works perfectly for splitting the Steam ID and working out the 64-bit community ID:

$split = explode(":", $steamid); // STEAM_?:?:??????? format

$x = substr($split[0], 6, 1);
$y = $split[1];
$z = $split[2];

$w = ($z * 2) + 0x0110000100000000 + $y;

$w will be the correctly formatted ID. I thought this may be helpful since I found this trying to do the same thing :)

Crashdoom
  • 31
  • 1
3

PHP don't have 64bit int on 32-bit binary. It is using floating point here. see how to have 64 bit integer on PHP?

The question include links to BC Math, which can be used for your problem.

Community
  • 1
  • 1
J-16 SDiZ
  • 26,473
  • 4
  • 65
  • 84
1

I have had the issue. I'm using xampp on windows and its using the 32bit version of php but i just finished making a working script :) it can convert 64bit steamid's to 32bit and back have a mess with it.

<?php
//Starting 64bit steamid
$steamid = "76561198086186258";
echo "Original 64bit steamid: $steamid";

//64bit steamid to 32bit below
$authserver = bcsub($steamid, '76561197960265728') & 1;
$authid = (bcsub($steamid, '76561197960265728')-$authserver)/2;
$steamid = "STEAM_0:$authserver:$authid";
echo "<br/>32bit steamid: $steamid";

//32bit steamid to 64bit below
$id = explode(":", $steamid);
$authserver = $id[1];
$steamid64 = $id[2];
$steamid64 = $steamid64 * 2;
$steamid64 = bcadd($steamid64, 61197960265728);
if ($authserver == 1){$steamid64 = $steamid64 + 1;};
$steamid64 = "765$steamid64";
echo "<br/>new 64bit steamid: $steamid64";
?>
Scott Fisk
  • 11
  • 1
0

Very old topic but just wanted to share how I solved it since I had 32bit PHP and no possibility of using BCMath on my host. (thanks SiPlus for solution)

Here's a snippet:

# Convert Steam ID to Steam64 ID
$idParts = explode(':', $tradeOwnerSteamId32);
$authServer = intval($idParts[1]);
$accountNumber = intval($idParts[2]);
$tradeOwnerSteamId64 = (string) $accountNumber * 2 + $authServer;

//And using it in URL

$depositorInventory = json_decode(file_get_contents("https://steamcommunity.com/profiles/[U:1:$tradeOwnerSteamId64]/inventory/json/730/2"), true);
0

You may use the BC Math PHP extension. Here is a snippet:

//STEAM_0:1:1514332

$a = bcadd(bcadd((1514332 * 2), 76561197960265728), 1);
echo $a; //76561197963294393
scube
  • 1,931
  • 15
  • 21
  • Did you get the same result from this? Because the `76561197963294000 ` is still the incorrect calculation. Unfortunately this is not working for any steam id conversions. – grep Aug 16 '11 at 07:53
  • No i "miss copy/pasted" your comment :) I get: 76561197963294393 – scube Aug 16 '11 at 07:57
0

try to add (string) before these calculations

$a = (string) (1514332 * 2) + 76561197960265728 + 1;

and it will work always;

demo

response: 76561197963294393

genesis
  • 50,477
  • 20
  • 96
  • 125
0

Using the BCMath extension, you can do the following:

bcadd(bcadd(bcmul('1514332', '2'), '76561197960265728'), 1)

Which is a conversion of the equation above. It returns a string and not an int, thus avoiding the 32bit int problem.

Seldaek
  • 40,986
  • 9
  • 97
  • 77
0

You are not doing anything wrong. The formula is correct (using a calculator I get the 'actual' number).

There must be either a rounding or calculating issue or a simple OS limit for it.

Devator
  • 3,686
  • 4
  • 33
  • 52