How to get IP Address in Cakephp
I am writing this blog which will let you know how to get client's IP Address in Cakephp. The simplest way for getting client's IP Address in core php is $_SERVER['REMOTE_ADDR']
. Similarly it is very easy to get IP Address in Cakephp.
In CakePHP 1.x:
RequestHandlerComponent::getClientIp();
Include RequestHandler in components in this way:
public $components = array(
'RequestHandler'
);
Then in the controller method:
$this->RequestHandler->getClientIp();
In CakePHP 2.x:
RequestHandler::getClientIp()
is deprecated; you can get the client IP from the CakeRequest
object:
$this->request->clientIp();
Thats all !
Thanks for reading the blog.
0 Comment(s)