Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (isset($_GET['login'])){
- require 'openid.php';
- try {
- require 'SteamConfig.php';
- $openid = new LightOpenID($steamauth['domainname']);
- if(!$openid->mode) {
- $openid->identity = 'http://steamcommunity.com/openid';
- header('Location: ' . $openid->authUrl());
- } elseif ($openid->mode == 'cancel') {
- echo 'User has canceled authentication!';
- } else {
- if($openid->validate()) {
- ///////////////////////////////////////////////////////////////
- $_STEAMAPI = "APIKEY";/////change////
- $servername = "HOST";/////change////
- $username = "USERNAME";/////change////
- $password = "PASSWORD";/////change////
- $dbname = "DATABASENAME";/////change////
- $con = new mysqli($servername, $username, $password, $dbname);
- if ($con->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- function get_client_ip_env()
- {
- $ipaddress = '';
- if (getenv('HTTP_CLIENT_IP'))
- $ipaddress = getenv('HTTP_CLIENT_IP');
- else if(getenv('HTTP_X_FORWARDED_FOR'))
- $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
- else if(getenv('HTTP_X_FORWARDED'))
- $ipaddress = getenv('HTTP_X_FORWARDED');
- else if(getenv('HTTP_FORWARDED_FOR'))
- $ipaddress = getenv('HTTP_FORWARDED_FOR');
- else if(getenv('HTTP_FORWARDED'))
- $ipaddress = getenv('HTTP_FORWARDED');
- else if(getenv('REMOTE_ADDR'))
- $ipaddress = getenv('REMOTE_ADDR');
- else
- $ipaddress = 'UNKNOWN';
- return $ipaddress;
- }
- $ipaddress=get_client_ip_env();
- ///////////////////////////////////////////////////////////////
- $id = $openid->identity;
- $ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
- preg_match($ptn, $id, $matches);
- $_SESSION['steamid'] = $matches[1];
- if (!headers_sent()) {
- ///////////////////////////////////////////////////////////////
- $url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$_STEAMAPI&steamids=$matches[1]";
- $json_object= file_get_contents($url);
- $json_decoded = json_decode($json_object);
- foreach ($json_decoded->response->players as $player)
- {
- $sql="SELECT * FROM users WHERE uid = $player->steamid";
- if ($result=mysqli_query($con,$sql))
- {
- $finalresult=mysqli_num_rows($result);
- mysqli_free_result($result);
- }
- if($finalresult == 0)
- {
- $insert=("INSERT INTO users (uid, name, ip, playerLevel) VALUES ('" . $player->steamid . "', '" . $player->personaname . "', '$ipaddress', '$finalresult')");
- mysqli_query($con, $insert);
- }
- }
- ///////////////////////////////////////////////////////////////
- header('Location: '.$steamauth['loginpage']);
- exit;
- } else {
- ?>
- <script type="text/javascript">
- window.location.href="<?=$steamauth['loginpage']?>";
- </script>
- <noscript>
- <meta http-equiv="refresh" content="0;url=<?=$steamauth['loginpage']?>" />
- </noscript>
- <?php
- exit;
- }
- } else {
- echo "User is not logged in.\n";
- }
- }
- } catch(ErrorException $e) {
- echo $e->getMessage();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement