Advertisement
Guest User

Untitled

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