Advertisement
Guest User

Untitled

a guest
Feb 1st, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.17 KB | None | 0 0
  1. <?php
  2. if (isset($_GET['login'])){
  3.     require 'openid.php';
  4.     try {
  5.         require 'SteamConfig.php';
  6.         $openid = new LightOpenID($steamauth['domainname']);
  7.        
  8.         if(!$openid->mode) {
  9.             $openid->identity = 'http://steamcommunity.com/openid';
  10.             header('Location: ' . $openid->authUrl());
  11.         } elseif ($openid->mode == 'cancel') {
  12.             echo 'User has canceled authentication!';
  13.         } else {
  14.             if($openid->validate()) {
  15.                 ///////////////////////////////////////////////////////////////
  16.                 $_STEAMAPI = "APIKEY";/////change////
  17.                 $servername = "HOST";/////change////
  18.                 $username = "USERNAME";/////change////
  19.                 $password = "PASSWORD";/////change////
  20.                 $dbname = "DATABASENAME";/////change////
  21.                
  22.                 $con = new mysqli($servername, $username, $password, $dbname);
  23.                 if ($con->connect_error) {
  24.                     die("Connection failed: " . $conn->connect_error);
  25.                 }
  26.                 function get_client_ip_env()
  27.                 {
  28.                     $ipaddress = '';
  29.                     if (getenv('HTTP_CLIENT_IP'))
  30.                         $ipaddress = getenv('HTTP_CLIENT_IP');
  31.                     else if(getenv('HTTP_X_FORWARDED_FOR'))
  32.                         $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
  33.                     else if(getenv('HTTP_X_FORWARDED'))
  34.                         $ipaddress = getenv('HTTP_X_FORWARDED');
  35.                     else if(getenv('HTTP_FORWARDED_FOR'))
  36.                         $ipaddress = getenv('HTTP_FORWARDED_FOR');
  37.                     else if(getenv('HTTP_FORWARDED'))
  38.                         $ipaddress = getenv('HTTP_FORWARDED');
  39.                     else if(getenv('REMOTE_ADDR'))
  40.                         $ipaddress = getenv('REMOTE_ADDR');
  41.                     else
  42.                         $ipaddress = 'UNKNOWN';
  43.                     return $ipaddress;
  44.                 }
  45.                 $ipaddress=get_client_ip_env();
  46.                 ///////////////////////////////////////////////////////////////
  47.                 $id = $openid->identity;
  48.                 $ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
  49.                 preg_match($ptn, $id, $matches);
  50.                
  51.                 $_SESSION['steamid'] = $matches[1];
  52.                 if (!headers_sent()) {
  53.                     ///////////////////////////////////////////////////////////////
  54.                     $url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$_STEAMAPI&steamids=$matches[1]";
  55.                     $json_object= file_get_contents($url);
  56.                     $json_decoded = json_decode($json_object);
  57.  
  58.                     foreach ($json_decoded->response->players as $player)
  59.                     {
  60.                         $sql="SELECT * FROM users WHERE uid = $player->steamid";
  61.                         if ($result=mysqli_query($con,$sql))
  62.                           {
  63.                           $finalresult=mysqli_num_rows($result);
  64.                           mysqli_free_result($result);
  65.                           }
  66.                         if($finalresult == 0)
  67.                         {
  68.                             $insert=("INSERT INTO users (uid, name, ip, playerLevel) VALUES ('" . $player->steamid . "', '" . $player->personaname . "', '$ipaddress', '$finalresult')");
  69.                             mysqli_query($con, $insert);
  70.                         }
  71.                     }
  72.                     ///////////////////////////////////////////////////////////////
  73.                     header('Location: '.$steamauth['loginpage']);
  74.                     exit;
  75.                 } else {
  76.                     ?>
  77.                     <script type="text/javascript">
  78.                         window.location.href="<?=$steamauth['loginpage']?>";
  79.                     </script>
  80.                     <noscript>
  81.                         <meta http-equiv="refresh" content="0;url=<?=$steamauth['loginpage']?>" />
  82.                     </noscript>
  83.                     <?php
  84.                     exit;
  85.                 }
  86.             } else {
  87.                 echo "User is not logged in.\n";
  88.             }
  89.         }
  90.     } catch(ErrorException $e) {
  91.         echo $e->getMessage();
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement