We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

request getClientAddress

Hello, when i am using request ->getClientAddress() i am getting return value 'false', when i look at the source code here i am suppose to get the value from $_SERVER["REMOTE_ADDR"].But the value in the superglobal is :::1, why i am getting false ?



5.1k
edited Jul '17

Hello

What is your environment

in windows 7 with chrome and wamp latest version, phacon 3.2.0,


$var = $this->request->getClientAddress(); 

$var dump give me : string '::1' (length=3)



1.5k
edited Jul '17
  • Phalcon version: 3.2.1
  • PHP Version: PHP 7.0.20-1~dotdeb+8.2
  • Operating System: Debian Jessie
  • Installation type: installing via package manager
  • Zephir version (if any): 0.9.9-868cb1f92b
  • Server: Apache2


5.1k
edited Jul '17

In my Debian Jessie vps

Phalcon version: 3.2.1 PHP Version: PHP 7.1.7 Server: Apache2

$var dump give me my ipv4 address (string xxx.xxx.xxx.xxx (length=15))

it's in your configuration but what, you use a proxy ?

have you check $_SERVER["HTTP_X_FORWARDED_FOR"] and $_SERVER["HTTP_CLIENT_IP" if it is set, the code does not do this code


        if address === null {
            fetch address, _SERVER["REMOTE_ADDR"];
        }


1.5k
  • 'REDIRECT_STATUS' => string '200' (length=3)
  • 'HTTP_HOST' => string 'localhost' (length=9)
  • 'HTTP_CONNECTION' => string 'keep-alive' (length=10)
  • 'HTTP_CACHE_CONTROL' => string 'max-age=0' (length=9)
  • 'HTTP_UPGRADE_INSECURE_REQUESTS' => string '1' (length=1)
  • 'HTTP_USER_AGENT' => string 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36' (length=104)
  • 'HTTP_ACCEPT' => string 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8' (length=74)
  • 'HTTP_ACCEPT_ENCODING' => string 'gzip, deflate, sdch, br' (length=23)
  • 'HTTP_ACCEPT_LANGUAGE' => string 'en-US,en;q=0.8,bg;q=0.6' (length=23)
  • 'HTTP_COOKIE' => string 'PHPSESSID=licj1ivb9dhjujo7cupdohrj41; RMU=KtWg970ipO1XQ8DpgBqmU1o%3D; RMT=WBjMXFF30hm3SdBns0r7BP12ZdYdLmaNmVCsqpOMsCbnTc3yHxrAIwDI%2Bxx7d6HN' (length=140)
  • 'PATH' => string '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' (length=60)
  • 'SERVER_SIGNATURE' => string '<address>Apache/2.4.10 (Debian) Server at localhost Port 80</address>
  • ' (length=70)
  • 'SERVER_SOFTWARE' => string 'Apache/2.4.10 (Debian)' (length=22)
  • 'SERVER_NAME' => string 'localhost' (length=9)
  • 'SERVER_ADDR' => string '::1' (length=3)
  • 'SERVER_PORT' => string '80' (length=2)
  • 'REMOTE_ADDR' => string '::1' (length=3)
  • 'DOCUMENT_ROOT' => string '/var/www/html' (length=13)
  • 'REQUEST_SCHEME' => string 'http' (length=4)
  • 'CONTEXT_PREFIX' => string '' (length=0)
  • 'CONTEXT_DOCUMENT_ROOT' => string '/var/www/html' (length=13)
  • 'SERVER_ADMIN' => string '[email protected]' (length=19)
  • 'SCRIPT_FILENAME' => string '/var/www/html/test/public/index.php' (length=35)
  • 'REMOTE_PORT' => string '36015' (length=5)
  • 'REDIRECT_URL' => string '/test/' (length=6)
  • 'GATEWAY_INTERFACE' => string 'CGI/1.1' (length=7)
  • 'SERVER_PROTOCOL' => string 'HTTP/1.1' (length=8)
  • 'REQUEST_METHOD' => string 'GET' (length=3)
  • 'QUERY_STRING' => string '' (length=0)
  • 'REQUEST_URI' => string '/test/' (length=6)
  • 'SCRIPT_NAME' => string '/test/public/index.php' (length=22)
  • 'PHP_SELF' => string '/test/public/index.php' (length=22)
  • 'REQUEST_TIME_FLOAT' => float 1500385309.58
  • 'REQUEST_TIME' => int 1500385309


5.1k
edited Jul '17

Not the proxy, no more ideas for me,

i think you have dump the request variable and it is initialized you can try to post your code

edited Jul '17

That's IPv6 address, i.e. your own loopback interface - configure your server to have IPv6 disabled.



1.5k

Hello,

when i call $this->request->getServer("REMOTE_ADDR") i am getting ::1, but when i call $this->request->getClientAddress() i am getting false, how is that possible ?, also when i am making ajax request $this->request->isAjax is returning false but when i call $this->request->getServer("HTTP_X_REQUESTED_WITH") i am getting XMLHttpRequest

edited Aug '17

Did you follow my reply here that you're getting your own localhost in IPv6 format? What is not clear about that? Try accessing your server/app from elsewhere but your own server/workstation.

If it still fails, your app and/or server are badly configured.

I guess your Router componenet and web server are not playing nice together. Post your web and Phalcon bootstrap (services) config.



1.5k
Accepted
answer

It was one of the composer packages i have installed, it was doing some crazy shits on all the superglobal variables