Advertisement
Guest User

Untitled

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