user1012181
user1012181

Reputation: 8726

$_SERVER['REMOTE_ADDR'] not returning IP address

I'm trying to get the client IP address using the code $_SERVER['REMOTE_ADDR'].

When I tried to dd($_SERVER['REMOTE_ADDR']), it gives me the following output.

string '::1' (length=3)

What's the reason? Am I doing it wrong?

My target is to identify the user location based on the IP address and calling an external API.

Upvotes: 1

Views: 2596

Answers (1)

Get Off My Lawn
Get Off My Lawn

Reputation: 36299

When you have a server on say your laptop, and you try to access it from the same laptop, the website sees it as it self and is represented in many different ways, and here are a few:

127.0.0.1
::1
localhost

To see the IP of your computer you can do the following:

  1. Put your website on a remote server then access it, this will give you your Public IP address.
  2. Put your website on another server on the same network and access it from a different computer on that network, and this will give the internal IP address for that computer.

Upvotes: 3

Related Questions