Category: Utility Classes

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

Hi,

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

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

I always get output:

::1

Please help, thanks!

SOLVED ip
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 127.0.0.1 address

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

Kristi
Kristi

137

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: 1967

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