steamid_converter.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php /*
  2. SteamID conversion tool by 8088 & KoST
  3. For more info, visit AlliedModders @ http://forums.alliedmods.net/showthread.php?t=60899
  4. */
  5. ?>
  6. <form method="get" action="">
  7. <div >
  8. <fieldset style="color:white;background-color:DarkSlateGray">
  9. <legend style="background-color:DarkSlateGray;color:white">Input</legend>
  10. <table>
  11. <tbody style="color:white;background-color:DarkSlateGray">
  12. <tr>
  13. <td>SteamID / FriendID / customURL:<br>
  14. <input type="hidden" size="70" name="m" value="<?php echo $_GET['m']; ?>">
  15. <input type="text" size="70" name="s" value="<?php echo htmlentities(stripslashes(@$_GET['s']),ENT_QUOTES); ?>">
  16. </td>
  17. </tr>
  18. <tr>
  19. <td align="right">
  20. <input class="button" type="submit" accesskey="s" value="Submit">
  21. </td>
  22. </tr>
  23. </tbody>
  24. </table>
  25. </fieldset>
  26. </div>
  27. </form>
  28. <?php
  29. $ret=get_input_type(@$_GET['s']);
  30. if ($ret==''){
  31. }else if (is_string($ret)){
  32. echo '<div><fieldset style="background-color:DarkSlateGray;color:white"><legend style="background-color:DarkSlateGray;color:white">Output</legend><table><tbody style="background-color:DarkSlateGray;color:white"><tr><td>';
  33. echo $ret;
  34. echo '</td></tr></tbody></table></fieldset>';
  35. if ($_GET['s']!=='') { echo $notice; }
  36. echo '</div>';
  37. }else if (is_array($ret)){
  38. echo '<div><fieldset style="background-color:DarkSlateGray;color:white"><legend style="background-color:DarkSlateGray;color:white">Output</legend><table><tbody style="background-color:DarkSlateGray;color:white"><tr><td>';
  39. convert($ret['type'],$ret['data']);
  40. echo '</td></tr></tbody></table></fieldset>';
  41. if ($_GET['s']!=='') { echo @$notice;}
  42. echo '</div>';
  43. }
  44. function convert($type,$data){
  45. switch($type){
  46. case 'steamid':
  47. $main='http://steamcommunity.com/profiles/'.bcadd((($data['auth']*2)+$data['server']),'76561197960265728');
  48. echo 'FriendID: <a href="'.$main.'" title="Visit Steam Community page" target="blank">'.bcadd((($data['auth']*2)+$data['server']),'76561197960265728').'</a>';
  49. break;
  50. case 'friendid':
  51. if (substr($data,-1)%2==0) $server=0; else $server=1;
  52. $auth=bcsub($data,'76561197960265728');
  53. if (bccomp($auth,'0')!=1) {echo "Error: invalid FriendID or SteamID";return;}
  54. $auth=bcsub($auth,$server);
  55. $auth=bcdiv($auth,2);
  56. echo "SteamID for VALVe's GoldSrc and Source Orange Box Engine games:<br>".
  57. 'STEAM_0:'.$server.':'.$auth;
  58. echo "<br><br>SteamID for VALVe's newer games:<br>".
  59. 'STEAM_1:'.$server.':'.$auth;
  60. break;
  61. }
  62. }
  63. function get_input_type($data){
  64. $data=strtolower(trim($data));
  65. if ($data!='') {
  66. if (strlen($data)>80) return "too long";
  67. if (substr($data,0,7)=='steam_0' or substr($data,0,7)=='steam_1') {
  68. $tmp=explode(':',$data);
  69. if ((count($tmp)==3) && is_numeric($tmp[1]) && is_numeric($tmp[2])){
  70. return array('type'=>'steamid','data'=>array('auth'=>$tmp[2],'server'=>$tmp[1]));
  71. }else{
  72. return "Error: invalid SteamID";
  73. }
  74. }else if ($p=strrpos($data,'/')){
  75. $tmp=explode('/',$data);
  76. foreach ($tmp as $item){
  77. if (is_numeric($item)){
  78. $a=$item;
  79. break;
  80. }
  81. }
  82. if ((is_numeric($a)) && (preg_match('/7656119/', $a))) return array('type'=>'friendid','data'=>$a);
  83. else {
  84. $xml = @simplexml_load_file($data."?xml=1");
  85. $steamid64=$xml->steamID64;
  86. if (!preg_match('/7656119/', $steamid64)) return "Error: invalid link";
  87. else return array('type'=>'friendid','data'=>$steamid64);
  88. }
  89. }else if ((is_numeric($data)) && (preg_match('/7656119/', $data))){
  90. return array('type'=>'friendid','data'=>$data);
  91. }else{
  92. $xml = @simplexml_load_file("http://steamcommunity.com/id/".$data."?xml=1");
  93. $steamid64=$xml->steamID64;
  94. if (!preg_match('/7656119/', $steamid64)) return "Error: invalid input";
  95. else return array('type'=>'friendid','data'=>$steamid64);
  96. }
  97. }else{
  98. return "";
  99. }
  100. }
  101. ?>