Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter 2 $this->ip_address() not returning ip address

Well, I'm trying to log user login history, so for this I need to track user's ip address. I used:

$this->input->ip_address();

This should return the ip address of the machine, if user has valid ip, or should return 0.0.0.0 if the user doesn't have a valid IP. But in my case it's returning neither.

It is returning just an unusual format.

::1

P.S. I'm checking it in my local computer.

EDIT :

Thanks all who commented. But still it is strange things going out here. I have two separate applications running in my same machine. Both applications are made in Codeigniter 2. The first one records 0.0.0.0 and the second one records ::1. Isnt both application should have returned same thing?

Thanks

like image 237
WatsMyName Avatar asked Sep 09 '12 13:09

WatsMyName


2 Answers

::1 is a valid IP address.

http://en.wikipedia.org/wiki/IPv6

like image 191
Tchoupi Avatar answered Nov 08 '22 01:11

Tchoupi


It may be worth checking if ::1 is present in your hosts file, and comment it out just to see if both of your applications then behave the same.

This thread has some useful info: http://codeigniter.com/forums/viewthread/205222

In particular

So your machine is running dual stack (which most modern OS’ses do these days), and when they do, they prefer IPv6 over IPv4.

Either remove IPv6 from your localhost interface, remove IPv6 support from your local webserver (have it only listen to your v4 address), [snipped]

like image 38
casaram Avatar answered Nov 08 '22 01:11

casaram