'Convert SteamID64 to SteamID

I'm looking for a way that I can take a SteamID64 (76561198032122624) and convert it to a SteamID (STEAM_0:0:35928448) in PHP. I've searched this quite a bit and I'm unable to find how to do this. I'm almost sure it's possible since sites like steamid.io are able to find it, but I don't know how.



Solution 1:[1]

function steamid64_to_steamid2($steamid64) {
    $accountID = bcsub($steamid64, '76561197960265728');
    return 'STEAM_0:'.bcmod($accountID, '2').':'.bcdiv($accountID, 2);
}

Solution 2:[2]

<?php 

$steamid64="76561198237914532"; //YOUR STEAM ID 64

echo "<-- By BigBossPT to VynexGaming.com -->";
echo "<br><br>Steamid32: ".getSteamId32($steamid64);
echo "<br><br>Steamid64: ".getSteamID64(getSteamId32($steamid64)); // 76561197985756607 
echo "<br><br>Thanks for Gio! Website that i found: https://facepunch.com/showthread.php?t=1238157";
//OBTER STEAM ID 64 

function getSteamID64($id) {
    if (preg_match('/^STEAM_/', $id)) {
        $parts = explode(':', $id);
        return bcadd(bcadd(bcmul($parts[2], '2'), '76561197960265728'), $parts[1]);
    } elseif (is_numeric($id) && strlen($id) < 16) {
        return bcadd($id, '76561197960265728');
    } else {
        return $id; // We have no idea what this is, so just return it.
    }
}


function parseInt($string) {
    //    return intval($string);
        if(preg_match('/(\d+)/', $string, $array)) {
            return $array[1];
        } else {
            return 0;
        }
    }
function getSteamId32($id){
    // Convert SteamID64 into SteamID

    $subid = substr($id, 4); 
    $steamY = parseInt($subid);
    $steamY = $steamY - 1197960265728; //76561197960265728

    if ($steamY%2 == 1){
    $steamX = 1;
    } else {
    $steamX = 0;
    }

    $steamY = (($steamY - $steamX) / 2);
    $steamID = "STEAM_0:" . (string)$steamX . ":" . (string)$steamY;
    return $steamID;

}
?>

Solution 3:[3]

This is an actual working version that does not require the BC Math PHP Extension.

<?php
    $id = "{STEAMID64 HERE}";

function parseInt($string) {
//    return intval($string);
    if(preg_match('/(\d+)/', $string, $array)) {
        return $array[1];
    } else {
        return 0;
    }}

// Convert SteamID64 into SteamID
$subid = substr($id, 4); // because calculators suck
$steamY = parseInt($subid);
$steamY = $steamY - 1197960265728; //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;

?>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ilia
Solution 2 Richard O'Brien
Solution 3