CakePHP Get IP Address

后端 未结 6 2030
小鲜肉
小鲜肉 2021-01-07 18:13

How can I get the client\'s IP address in CakePHP? It\'d be $_SERVER[\'REMOTE_ADDR\'] in plain PHP.

I thought it\'s like all $_SERVER vars

6条回答
  •  臣服心动
    2021-01-07 18:22

    You can use $this->request->clientIp(); to get the current visitor's IP address.

    Cake\Http\ServerRequest::clientIp()
    Returns the current visitor’s IP address.
    

    For further reference https://book.cakephp.org/3.0/en/controllers/request-response.html#reading-http-headers

提交回复
热议问题