Welcome to The Forum

Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads

[Translate Steamid] Function.


Recommended Posts

Well hai there!

 

I have been strugling to find a way to translate steamid from string into a community page url.

 

 

steamid = $_POST['steamid'];

 

next I need to remove the STEAM_0: <-- part of the string so its left with either 0: or 1: + the rest of the steamid

 

now I need to multply the part that is (after STEAM_0:1or0:) (example STEAM_0:1:123456 * 2) with 2 obviously.

 

now if it was STEAM_0:1 (aka 1) you have to add the multplied subject above (example 123456 * 2 + 1) or (example 123456 * 2 + 0)

depending if there is STEAM_0:1 or STEAM_0:0

 

then I need to add the result + 76561197960265728 = communityid to (steam_0:1:123456)

 

Anyways I'm not that good in php, I would apriciate any help possible.

This could be in a function or just simply a sample script, or suggestions are welcome aswell.

 

I could donate 5$ if nessesary.

 

Thanks again upfront.

Link to comment
Share on other sites

function getFriendId($steamId)
{
//Test input steamId for invalid format
//Example SteamID: "STEAM_X:Y:ZZZZZZZZ"
$gameType = 0; //This is X. It's either 0 or 1 depending on which game you are playing (CSS, L4D, TF2, etc)
$authServer = 0; //This is Y. Some people have a 0, some people have a 1
$clientId = ''; //This is ZZZZZZZZ.
//Remove the "STEAM_"
$steamId = str_replace('STEAM_', '' ,$steamId);
//Split steamId into parts
$parts = explode(':', $steamId);
$gameType = $parts[0];
$authServer = $parts[1];
$clientId = $parts[2];
//Calculate friendId
$result = bcadd((bcadd('76561197960265728', $authServer)), (bcmul($clientId, '2')));
return $result;
}

 

Took all of five seconds to search on google, it is fairly simply to code as well...

Edited by Papa John
Link to comment
Share on other sites

well something went wrong..

 

function getFriendId($steamId)
{
//Test input steamId for invalid format
//Example SteamID: "STEAM_X:Y:ZZZZZZZZ"
$gameType = 0; //This is X. It's either 0 or 1 depending on which game you are playing (CSS, L4D, TF2, etc)
$authServer = 0; //This is Y. Some people have a 0, some people have a 1
$clientId = ''; //This is ZZZZZZZZ.
//Remove the "STEAM_"
$steamId = str_replace('STEAM_', '' ,$steamId);
//Split steamId into parts
$parts = explode(':', $steamId);
$gameType = $parts[0];
$authServer = $parts[1];
$clientId = $parts[2];
//Calculate friendId
$result = bcadd((bcadd('76561197960265728', $authServer)), (bcmul($clientId, '2')));
return $result;
}

 

if(empty($_POST) === false) {
$steamId = $_POST['steamid'];
echo '<a href="http://steamcommunity.com/profiles/' . getFriendId($steamId) . '">Community </a>';
}

 

Got wrong url and it added ,000000000 (the url that came with my steamid http://steamcommunity.com/profiles/76561197993906207.0000000000)

Edited by Priceless
Link to comment
Share on other sites

Ok, I guess I will just make one.

 


<?
public function SteamIDtoCommunityID($steamID)
{
// Remove extra STEAM_ in front
//Result: STEAM_0:X:XXXXXX -> 0:X:XXXXXX
$steamID = str_replace("STEAM_", "", $steamID);
// Explode splits the string at all :'s
//Result: 0:X:XXXXXX -> $steamID[0] = 0, $steamID[1] = X, $steamID[2] = XXXXXX
$steamID = explode(":", $steamID);
// Use Math
$steamID = ($steamID[2] * 2 + $steamID[1]) + 76561197960265728;
return "http://steamcommunity.com/profiles/" . $steamID;
}
?>

 

Now if your web host runs on a 32-bit system it obviously won't be able to compute a 64-bit number. If that is the case PHP does have a few functions to help you out but I will leave that for you to figure out.

Edited by Papa John
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share