开发者

CakePHP: $this->RequestHandler->getClientIP() doesn't do anything

In my hitcount system, I try to capture the IP of the current 'hitter' and keep this session for one hour.

Part of the function:

 $this->Session->write('hit_ip', $开发者_如何学Pythonthis->RequestHandler->getClientIP());

If I echo the hit_ip session, or:

 echo $this->RequestHandler->getClientIP());

It echo's '1::1'

How should I use this function? Yes I added the requestHandler to the Components var in my app_controller

Many thanks!


::1 is the client IP address.

If you're using this on a test server on your own computer, you're mostly likely opening it at the address http://localhost. Internally that's looped back to your own computer. The server can only tell you where it received the request from, which in the case of a local loopback request is the local loopback address. In IPv4 that used to be 127.0.0.1, in IPv6, which your computer is apparently preferring, that's ::1.

If you actually accessed the app from another computer, you'd see a different address.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜