Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get IP Address in Cakephp?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.82k
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: