Файл: Kagao-v3.0/upload/geo.php
Строк: 162
<?php
error_reporting(0);
$_GET['format'] = 'js';
//geoLocation
class geo
{
    var $url = 'http://www.ip-tracker.org/locator/ip-lookup.php?ip=';
    
    public function get_web_page( $url )
    {
        $user_agent='Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';
        $options = array(
            CURLOPT_CUSTOMREQUEST  =>"GET",        //set request type post or get
            CURLOPT_POST           =>false,        //set to GET
            CURLOPT_USERAGENT      => $user_agent, //set user agent
            CURLOPT_COOKIEFILE     =>"cookie.txt", //set cookie file
            CURLOPT_COOKIEJAR      =>"cookie.txt", //set cookie jar
            CURLOPT_RETURNTRANSFER => true,     // return web page
            CURLOPT_HEADER         => false,    // don't return headers
            CURLOPT_FOLLOWLOCATION => true,     // follow redirects
            CURLOPT_ENCODING       => "",       // handle all encodings
            CURLOPT_AUTOREFERER    => true,     // set referer on redirect
            CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
            CURLOPT_TIMEOUT        => 120,      // timeout on response
            CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
        );
        $ch      = curl_init( $url );
        curl_setopt_array( $ch, $options );
        $content = curl_exec( $ch );
        $err     = curl_errno( $ch );
        $errmsg  = curl_error( $ch );
        $header  = curl_getinfo( $ch );
        curl_close( $ch );
        $header['errno']   = $err;
        $header['errmsg']  = $errmsg;
        $header['content'] = $content;
        return $header;
    }
    
    public function load(){
        
        if($_SERVER['REMOTE_ADDR'] == '127.0.0.1'){ $ip = '95.33.249.10';    
        }else{ $ip = $_SERVER['REMOTE_ADDR']; }
        
        $open = $this->get_web_page($this->url . $ip);
        
        return $open['content'];
            
    }
    
    public function format($data, $format){
        
        switch($format){
        
            case 'js':
                
                $data = stripslashes($data);
                $inf = json_decode($data);
                
                $inf = (object) $inf;
                
                
                header('Content-Type: application/javascript');
                
                ?>
//SocialSoft Inc.
//package.socialsoft.geo.v1
//lastUserCacheKey: <?php echo date('d.m.Y h:i:s', $inf->lastcache); ?>
//lastUserFoundIP: <?php echo $inf->lastip; ?>
function geoip_latitude(){ return '<?php echo utf8_decode($inf->c_lati); ?>'; }
function geoip_longitude(){ return '<?php echo utf8_decode($inf->c_long); ?>'; }
function geoip_city(){ return '<?php echo $inf->city; ?>'; }
function geoip_state(){ return '<?php echo utf8_decode($inf->state); ?>'; }
function geoip_continent(){ return '<?php echo utf8_decode($inf->continent); ?>'; }
function geoip_country(){ return '<?php echo utf8_decode($inf->country); ?>'; }
function geoip_capital(){ return '<?php echo utf8_decode($inf->capital); ?>'; }
function geoip_postcode(){ return '<?php echo utf8_decode($inf->postcode); ?>'; }
<?php
                
            break;
        
            default:
                return $data;
            break;
            
        }
            
    }
    
    public function html($ext){
        
        $ext = str_replace(' ', '', $ext);
        $ext = str_replace('(', '', $ext);
        $ext = str_replace(')', '', $ext);
        
        return $ext;
            
    }
    
    public function start($format = false){
        
        
        if(empty($_COOKIE['jsonData_111'])){
        
        $data = $this->load();
        
        $info = preg_match_all('|<table cellpadding=0 cellspacing=7 width=480 height=100% border=0 align=left>(.*?)</table>|is', $data, $ende);
        $info = $ende[1][0];
        
        $continent     = preg_match_all("|<tr><th>Continent:</th><td class='tracking'>(.*?)</td></tr>|", $info, $cont);
        $country     = preg_match_all("|<tr><th>Country:</th><td>(.*?)</td></tr>|", $info, $cout);
        $stadt         = preg_match_all("|<tr><th>Capital:</th><td class='tracking'>(.*?)</td></tr>|", $info, $stad);
        $bundes     = preg_match_all("|<tr><th>State:</th><td class='tracking lessimpt'>(.*?)</td></tr>|", $info, $bland);
        $cityrr     = preg_match_all("|<tr><th>City Location:</th><td class='vazno'>(.*?)</td></tr>|", $info, $city);
        $postleit     = preg_match_all("|<tr><th>Postal:</th><td class='tracking less3impt'>(.*?)</td></tr>|", $info, $plz);
        
        //lat/lon
        $cityLat    = preg_match_all("|<tr><th>City Lat/Lon:</th><td class='tracking'>(.*?)</td></tr>|", $info, $citylatlong);
        
        
        //city->Lat
        $citylati = explode(' / ', $citylatlong[1][0]);
        $cityLatitude = $this->html(trim($citylati[0]));
        $cityLongtude = $this->html(trim($citylati[1]));
        
        $data = array(
            "continent"    => $cont[1][0],
            "country"    => str_replace(' ', '', strip_tags($cout[1][0]) ),
            "capital"    => utf8_encode($stad[1][0]),
            "state"        => utf8_encode($bland[1][0]),
            "city"        => utf8_encode($city[1][0]),
            "postcode"    => $plz[1][0],
            "lastcache"    => time(),
            "lastip"    => $_SERVER['REMOTE_ADDR'],
            "c_lati"    => $cityLatitude,
            "c_long"    => $cityLongtude
            
        );
        
        $jsonDataCompressed = json_encode($data, true);
            
        setcookie("jsonData_111", $jsonDataCompressed, time()+(3600*24));
            
        echo $this->format($jsonDataCompressed, $_GET['format']);
            
        }else{
        
            echo $this->format($_COOKIE['jsonData_111'], $_GET['format']);
            
        }
        
    }
    
}
$init = new geo;
echo $init->start();
?>