简体   繁体   中英

$_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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM