Jump to content

Recommended Posts

Hello, it would be terrific if the below sum is possible with a php code.

 

The given information is:

id = STEAM_0:1:12345678

 

The sum is:

$sum = $result->id;

$sum = $sum - (first 10 characters); //result=12345678

$sum = $sum * 2; //result=24691356

$sum = $sum + 76561197960265728; //result=7656119845409284

$sum = $sum + (9Th character from $result->id); //result=7656119845409285

 

The result of the sum is:

76561197984957085

Link to comment
https://forums.phpfreaks.com/topic/146830-solved-need-a-code-for-this-sum/
Share on other sites

Result->id is a result of a query.

 

The below line maybe explain more as the words above.

 

$resource = mysql_query("SELECT bid, ip, id, nick, admin_id, admin_nick, ban_reason, ban_created, ban_length, server_ip, server_name FROM $config->bans ORDER BY ban_created DESC LIMIT ".$query_start.",".$query_end) or die(mysql_error());

while($result = mysql_fetch_object($resource)) {

$sum = Result->id;

 

 

 

I made a function for you:

 

function getSteamResult($id)
{
   $sum = substr($id, 10);
   $sum *= 2;                  //result=24691356
   $sum += 76561197960265728;  //result=7656119845409284
   $sum += substr($id, 10, 1);  //9Th character from $result->id) result=7656119845409285
   return $sum;
}

$id = "STEAM_0:1:12345678";
echo getSteamResult($id);
?>

* The above function is assuming that there will always be 10 characters before the actual calculating number.  (I'm almost positive it's always the same because I use to be addicted to CS:S, in fact the only difference I can remember is that the 1 changes to a 2 for banned accounts or something like that)

 

Just out of curiosity, what exactly is the purpose of this algorithm?  Seems so random...

Thank you very much Maq, in first case your code didn't seemed to work because i got a blank page but after removing some part of your code i got it finally to work.

 

The code i only left is below.

$community_id = substr($player_id, 10);

$community_id *= 2;

$community_id += 76561197960265728;

$community_id += substr($player_id, 10, 1);

 

$community_id is now the steam community id for the selected steamid and readed by the template file from the website. Maybe it's easier to see (link) what i mean as to read my explanation. When you click on a steamid you go automatically to his/her steam community id page thanks to your code!

One last question, both below codes do work correct but which code should i use, the one with 4 lines or the one everything in one line. The one all in one line is less to read/download, it sounds maybe silly but doesn't it use more CPU usage form the server?

 

$community_id	= substr($player_id, 10);
$community_id	*= 2;
$community_id	+= 76561197960265728;
$community_id	+= substr($player_id, 10, 1);

 

$community_id_new	= ( ( substr($player_id, 10) ) * 2 ) + 76561197960265728 + ( substr($player_id, 10, 1) );

The one all in one line is less to read/download, it sounds maybe silly but doesn't it use more CPU usage form the server?

 

I guess, because you are assigning $community_id a new value 4 times.  I think it's small enough that you won't be able to tell.  There's also fewer characters in the whole algorithm, other than that I don't think it makes any difference.

 

You can test it by outputting start and stop times in your script.

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.