Category: Utility Classes

Q: In Cakephp 3, how to get client's IP address?


How can I get client's true IP address in Cake 3? 

$clientIp = $_SERVER['REMOTE_ADDR']; //the php way

I always get output:


Please help, thanks!

2 Answers

Version: 3

I think the reason you are getting ::1 is because the localhost environment.

Should a MAMP return ::1 as IP on localhost?

::1 is the IVP6 equivalent of IVP4 address

You can also set your local ip address in Apache's config.



Accepted by AJhamper

::1 is the IVP6 address (Kristi's answer).

If you want to get client's ip address in cakephp way, consider: 

//in controller
$ip = $this->request->clientIp();

Created: 26 Sep '16

Last Reply: 26 Sep '16

Replies: 2

Views: 9100

Votes: 1

Welcome to Aero Coding!

Aero Coding is a CakePHP-focused Q&A community for professional and enthusiast cake bakers. It's built and run by you as part of the community.

Join Now Tour

Download Cakephp

Start baking your own CakePHP application!

Cakephp All Versions