title: how to get ip address in codeigniter?
body: <p>I am doing this following code for login attempt &amp; i want get IP address of my local machine..</p>
  
  <pre><code>if ( !$this-&gt;session-&gt;userdata('login_attempts') )
  {
     $this-&gt;session-&gt;set_userdata('login_attempts', 0);
  }
  $attempts = ($this-&gt;session-&gt;userdata('login_attempts') + 1);
  $this-&gt;session-&gt;set_userdata('login_attempts', $attempts);
  // Check if the session.
  if ( $this-&gt;session-&gt;userdata('login_attempts') &gt; 4 )
  {
      echo 'hi....login attempt is over';
  }
  // Failed. So, update the session    
  
  echo $ip = $_SERVER['REMOTE_ADDR'];
  // $ip_address = $this-&gt;input-&gt;ip_address1();
  // return $ip_address;
  echo $this-&gt;input-&gt;ip_address();
  if ( ! $this-&gt;input-&gt;valid_ip($ip))
  {
      echo 'Not Valid';
  }
  else
  {
      echo 'Valid';
  }
  $this-&gt;db-&gt;update('loginattempts',array( 'login_attempts' =&gt;$this-&gt;session-&gt;userdata('login_attempts') , 'lastLogin' =&gt;date('Y-m-d H:i:s'),'ip'=&gt;$ip = $_SERVER['REMOTE_ADDR'] ),array('login_id' =&gt;1) );
  echo ('hi....login attempt is'.$this-&gt;session-&gt;userdata('login_attempts'));
  
  }
  </code></pre>
  
  <p>but it show incorrect ip address of my local machine.</p>