Welcome Guest, Not a member yet? Register   Sign In
input->ip_address() - returns 2 different ip address on the same machine (connection)
#1

[eluser]czetsuya[/eluser]
Hi,

For record and security purposes we are tracking the ip address of the users. And I call the above method inside a model like this:

First, I get the CI instance:
Code:
$CI = & get_instance();

And get the value like this:
Code:
$CI->input->ip_address()

Unfortunately, I was surprised to see that the 2 calls return 2 different ip address:

1.) 64.94.x.x
2.) 202.123.x.x

What might be causing the problem :-?

Thanks,
czetsuya
#2

[eluser]khagendra[/eluser]
The codeigniter Input class is initializes automatically.

You just try this it will work. i have used just this and it is printing only one IP address.

Code:
echo $this->input->ip_address();

best of luck
#3

[eluser]czetsuya[/eluser]
Hi,

Thanks for the reply, unfortunately I'm still getting the 2 IPs, weird.

1.) 64.94.x.x
2.) 202.123.x.x

The correct IP is 202.123.x.x, where did 64.x.x.x came from :-?. As far as I know if get ip failed it should return 0.0.0.0.

I called the ip like this, and insert it directly to database:
Code:
//first - correct value
$data = array(
  'fname' => ucfirst($this->input->post('fname')),
  'lname' => ucfirst($this->input->post('lname')),
  'email' => $this->input->post('email'),
  'website' => $this->input->post('website'),
  'ip' => $this->input->ip_address()
  .
  .
);
$this->db->insert('tablea', $data);
//second - this produces wrong value
$data = array(
  'id' => $id,
  'ip' => $this->input->ip_address()
  .
);
$this->db->insert('tableb', $data);

czetsuya




Theme © iAndrew 2016 - Forum software by © MyBB