<?php

    
//Steam Auth Class by Sloenthran

    
class SteamAuth
    
{

        function 
GetURL()
        {
        
            
$Data = array(
                
'openid.ns'            => 'http://specs.openid.net/auth/2.0',
                
'openid.mode'        => 'checkid_setup',
                
'openid.return_to'    => (!empty($_SERVER['HTTPS']) ? 'https' 'http') . '://' $_SERVER['HTTP_HOST'] . '/steam_login.php',
                
'openid.realm'        => (!empty($_SERVER['HTTPS']) ? 'https' 'http') . '://' $_SERVER['HTTP_HOST'],
                
'openid.identity'    => 'http://specs.openid.net/auth/2.0/identifier_select',
                
'openid.claimed_id'    => 'http://specs.openid.net/auth/2.0/identifier_select',
            );
        
            return 
'https://steamcommunity.com/openid/login' '?' http_build_query($Data'''&');
            
        }    

        function 
Validate()
        {
        
            
$Data = array(
                
'openid.assoc_handle'    => $_GET['openid_assoc_handle'],
                
'openid.signed'            => $_GET['openid_signed'],
                
'openid.sig'            => $_GET['openid_sig'],
                
'openid.ns'                => 'http://specs.openid.net/auth/2.0',
            );
        
            
$Signed explode(','$_GET['openid_signed']);
        
            foreach(
$Signed as $Item)
            {
            
                
$Value $_GET['openid_' str_replace('.''_'$Item)];
                
$Data['openid.' $Item] = get_magic_quotes_gpc() ? stripslashes($Value) : $Value
            
            }

            
$Data['openid.mode'] = 'check_authentication';
            
            
$Query =  http_build_query($Data);
        
            
$Text stream_context_create(array(
                
'http' => array(
                    
'method'  => 'POST',
                    
'header'  => 
                        
"Accept-language: en\r\n".
                        
"Content-type: application/x-www-form-urlencoded\r\n" .
                        
"Content-Length: " strlen($Query) . "\r\n",
                    
'content' => $Query,
                ),
            ));

            
$Result file_get_contents('https://steamcommunity.com/openid/login'false$Text);
        
            
preg_match("#^http://steamcommunity.com/openid/id/([0-9]{17,25})#"$_GET['openid_claimed_id'], $Match);
        
            
$SID is_numeric($Match[1]) ? $Match[1] : 0;

            return 
preg_match("#is_valid\s*:\s*true#i"$Result) == $SID '';
        
        }
        
        function 
GetData($API$SID)
        {
            
            
$Query =  file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".$API."&steamids=".$SID);
            
            
$Fetch json_decode($Querytrue);
            
            return 
$Fetch;
            
        }
    
    }
    
?>