Subversion Repositories region

[/] [stable/] [1.0/] [classes/] [ezxISO3166.php] - Diff between revs 3 and 4

Show entire file | Ignore whitespace | Details | Blame | View Log

Rev 3 Rev 4
Line 3... Line 3...
{
{
    var $address;
    var $address;
    function ezxISO3166( $address = null )
    function ezxISO3166( $address = null )
    {
    {
        if ( !$address )
        if ( !$address )
           $this->address = $_SERVER['REMOTE_ADDR'];
           $this->address = ezxISO3166::getRealIpAddr();
        else
        else
           $this->address = $address;
           $this->address = $address;
 
    }
 
    function defautCountryCode()
 
    {
 
        $regionini = eZINI::instance( 'region.ini' );
 
        return strtoupper( $regionini->variable( 'Settings', 'DefaultCountryCode' ) );
 
    }
 
    function getRealIpAddr()
 
    {
 
        //check ip from share internet
 
        if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) )
 
        {
 
            $ip = $_SERVER['HTTP_CLIENT_IP'];
 
        }
 
        //to check ip is pass from proxy
 
        elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) )
 
        {
 
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
 
        }
 
        else
 
        {
 
            $ip = $_SERVER['REMOTE_ADDR'];
 
        }
 
        return $ip;
    }
    }
    function getALLfromIP()
    function getALLfromIP()
    {
    {
        // this sprintf() wrapper is needed, because the PHP long is signed by default
        // this sprintf() wrapper is needed, because the PHP long is signed by default
        $ipnum = sprintf("%u", ip2long( $this->address ));
        $ipnum = sprintf("%u", ip2long( $this->address ));
Line 138... Line 161...
    }
    }
    function preferredCountry()
    function preferredCountry()
    {
    {
        $ip = new ezxISO3166();
        $ip = new ezxISO3166();
        $code = $ip->getCCfromIP();
        $code = $ip->getCCfromIP();
 
        if( !$code )
 
            $code = ezxISO3166::defautCountryCode();
        $countries = ezxISO3166::countries();
        $countries = ezxISO3166::countries();
        if ( in_array( $code, $countries ) )
        if ( in_array( $code, $countries ) )
            return $code;
            return $code;
        else if( $code )
        else if( $code )
            return true;
            return true;