Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top