0

I am trying to use the function "clientIp", to get the real IP of the user, but this is not returning anything. I'm using this:

$ipAddr = $this->request->clientIp();
print_r($ipAddr);die();

And print it " ::1 "

instead of the actual ip print, print it ::1

anyone ever had this problem, how can I solve?

samuel_R
  • 501
  • 1
  • 5
  • 18

1 Answers1

2

Try this in cakephp 2.xx

$this->request->clientIp();

You can use native PHP server variable

$_SERVER['REMOTE_ADDR']

This is working example of my application on CakePhP

function get_realIp(){
  if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
        $_SERVER['REMOTE_ADDR']=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }elseif(isset($_SERVER['HTTP_X_REAL_IP']){
        $_SERVER['REMOTE_ADDR']=$_SERVER['HTTP_X_REAL_IP'];
    }
return $_SERVER['REMOTE_ADDR'];
}

let me know if i can help you more.

liyakat
  • 11,825
  • 2
  • 40
  • 46
  • I tested the 3 ways that you quoted, and the three are returning this one ::1 I'm testing this function on localhost, can it affect? – samuel_R Jul 05 '13 at 12:28
  • sorry you it will give you very time your local ip, you should require to test on some live ip. – liyakat Jul 05 '13 at 12:39
  • I put an example on a host online, and it worked correctly. Thank you for your help. – samuel_R Jul 05 '13 at 16:27