Welcome Guest, Not a member yet? Register   Sign In
Supporting IP6 when fetching and storing IP addresses
#1

[eluser]Xeoncross[/eluser]
I'm not sure how long we have until we make the jump to IP6, but the available IP4 addresses are supposed to be used up by 2011. So it make since that our apps should be ready to handle this new address types that our servers are already supporting.

For those of you unfamiler with IP6, it looks like this:
Code:
3ffe:1900:4545:3:200:f8ff:fe21:67cf

And can be abreivated in many ways:
Code:
2001:0db8:0000:0000:0000:0000:1428:57ab
2001:0db8:0000:0000:0000::1428:57ab
2001:0db8:0:0:0:0:1428:57ab
2001:0db8:0:0::1428:57ab
2001:0db8::1428:57ab
2001:db8::1428:57ab

Anyway, the current method we are using for IP checking is found on line 343 of the Input Class.
Code:
function ip_address()
    {
        if ($this->ip_address !== FALSE)
        {
            return $this->ip_address;
        }
        
        if (config_item('proxy_ips') != '' && $this->server('HTTP_X_FORWARDED_FOR') && $this->server('REMOTE_ADDR'))
        {
            $proxies = preg_split('/[\s,]/', config_item('proxy_ips'), -1, PREG_SPLIT_NO_EMPTY);
            $proxies = is_array($proxies) ? $proxies : array($proxies);

            $this->ip_address = in_array($_SERVER['REMOTE_ADDR'], $proxies) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
        }
        elseif ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP'))
        {
            $this->ip_address = $_SERVER['HTTP_CLIENT_IP'];
        }
        elseif ($this->server('REMOTE_ADDR'))
        {
            $this->ip_address = $_SERVER['REMOTE_ADDR'];
        }
        elseif ($this->server('HTTP_CLIENT_IP'))
        {
            $this->ip_address = $_SERVER['HTTP_CLIENT_IP'];
        }
        elseif ($this->server('HTTP_X_FORWARDED_FOR'))
        {
            $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR'];
        }

        if ($this->ip_address === FALSE)
        {
            $this->ip_address = '0.0.0.0';
            return $this->ip_address;
        }

        if (strstr($this->ip_address, ','))
        {
            $x = explode(',', $this->ip_address);
            $this->ip_address = trim(end($x));
        }

        if ( ! $this->valid_ip($this->ip_address))
        {
            $this->ip_address = '0.0.0.0';
        }

        return $this->ip_address;
    }

The problem is that is still the old IP4 format. Thanks to the inet_ntop() and inet_pton() we can convert either format into something that is easier to store. Here are some php functions for anyone interested.

So when is CodeIgniter going to support IP6 and what hurdles are there?


Messages In This Thread
Supporting IP6 when fetching and storing IP addresses - by El Forum - 09-07-2009, 01:04 PM
Supporting IP6 when fetching and storing IP addresses - by El Forum - 09-07-2009, 03:59 PM
Supporting IP6 when fetching and storing IP addresses - by El Forum - 09-07-2009, 04:03 PM
Supporting IP6 when fetching and storing IP addresses - by El Forum - 09-07-2009, 04:08 PM
Supporting IP6 when fetching and storing IP addresses - by El Forum - 09-07-2009, 04:11 PM
Supporting IP6 when fetching and storing IP addresses - by El Forum - 09-08-2009, 10:28 AM
Supporting IP6 when fetching and storing IP addresses - by El Forum - 09-08-2009, 03:45 PM
Supporting IP6 when fetching and storing IP addresses - by El Forum - 09-08-2009, 07:45 PM
Supporting IP6 when fetching and storing IP addresses - by El Forum - 09-08-2009, 08:06 PM



Theme © iAndrew 2016 - Forum software by © MyBB