Cakephp get ip Address


Cakephp get ip Address : In cakephp 2.x $this->request->clientIp(); is used to get the ip Address and In cakephp 1.x RequestHandlerComponent::getClientIp(); is used to get the ip address. You can use the as per your cakephp version. In this tutorial we are going to explain how to get the ip address of current user in cakephp.


Cakephp get ip Address

You can use the below syntax to get the address in cakephp as per the version-

In Cakephp 1.x

Use the below syntax to get the ip address in cakephp 1.x –

Cakephp get ip Address

$userIpAddress = RequestHandlerComponent::getClientIp();

Which will give you the current visitor ip address in cakephp 1.x.

In Cakephp 2.x

RequestHandlerComponent::getClientIp(); is deprecated in cakephp 2.x so use the below syntax to get the ip address in cakephp 2.x –

Cakephp get ip Address

$userIpAddress = $this->request->clientIp();

Which will give you the current visitor ip address in cakephp 2.x.

Note : You can still use the server variable $_SERVER[‘REMOTE_ADDR’] to get ip address.

Advertisements

Add Comment

📖 Read More