Maurice79 Posted February 25, 2009 Share Posted February 25, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/146830-solved-need-a-code-for-this-sum/ Share on other sites More sharing options...
JonnoTheDev Posted February 25, 2009 Share Posted February 25, 2009 What is this part? $sum = $result->id; What it the start value of $sum? Quote Link to comment https://forums.phpfreaks.com/topic/146830-solved-need-a-code-for-this-sum/#findComment-770881 Share on other sites More sharing options...
Maurice79 Posted February 25, 2009 Author Share Posted February 25, 2009 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; Quote Link to comment https://forums.phpfreaks.com/topic/146830-solved-need-a-code-for-this-sum/#findComment-770982 Share on other sites More sharing options...
Maq Posted February 25, 2009 Share Posted February 25, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/146830-solved-need-a-code-for-this-sum/#findComment-770993 Share on other sites More sharing options...
Maq Posted February 25, 2009 Share Posted February 25, 2009 * 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... Quote Link to comment https://forums.phpfreaks.com/topic/146830-solved-need-a-code-for-this-sum/#findComment-771003 Share on other sites More sharing options...
Maurice79 Posted February 26, 2009 Author Share Posted February 26, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/146830-solved-need-a-code-for-this-sum/#findComment-771480 Share on other sites More sharing options...
Maq Posted February 26, 2009 Share Posted February 26, 2009 Oh ok, so that's steam's algorithm to create the steam community id for the profile page? Quote Link to comment https://forums.phpfreaks.com/topic/146830-solved-need-a-code-for-this-sum/#findComment-771784 Share on other sites More sharing options...
Maurice79 Posted February 26, 2009 Author Share Posted February 26, 2009 Yes it's the formule to convert any steamID to the steam communityID. There are some codes released already but none of them where wroking for me or so small as yours. Quote Link to comment https://forums.phpfreaks.com/topic/146830-solved-need-a-code-for-this-sum/#findComment-771973 Share on other sites More sharing options...
Maurice79 Posted February 26, 2009 Author Share Posted February 26, 2009 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) ); Quote Link to comment https://forums.phpfreaks.com/topic/146830-solved-need-a-code-for-this-sum/#findComment-772013 Share on other sites More sharing options...
Maq Posted February 26, 2009 Share Posted February 26, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/146830-solved-need-a-code-for-this-sum/#findComment-772084 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.