stevebauman / location

Detect a users location by their IP Address.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Location::get($ip); always returning false

Spepardy opened this issue · comments

I just installed this package, version "^5.2" in Laravel 7.0. I've always been getting "false" whenever I run Location::get($ip); in my localhost with any ip address I try with.
Your help will be well appreciated.
Thank you.

hello @Spepardy, this is most likely because the ip address on your localhost or local machine machine is something like ::1 or 127.0.0.1 which in this case isn't treated like an normal or correct IP address,


I had the same issue once but when you upload the project to a server you will realize that it works just perfectly, or maybe another way would be to make a query to any `IP API` and pick your if from the result of that call, that should also work just perfectly fine

Well stated @edmondsylar , that's exactly the IP addresses I get from my localhost.
But I thought if I manually enter an IP like "50.90.0.1" or "66.102.0.0" it should work fine. What about that please ? So I can use random IPs in development.
Thank you

yeah sure it should work.

@edmondsylar
Yeah, it works fine for those two IPs when I tried again. But it still returns false when I use my IP from ipconfig in cmd. What could be the reason please ?
Thank you

@Spepardy
the best way I can explain that to you is
That Ip you see in your ipconfig output Example 192.168.8.something is more like only recognized from within your local network but when making a request outside the network the packets carry the router IP which is exposed to the internet so its that IP address at work but not your actual machine ip since it stops at your network router together with your mac, so when response is back the router knows exactly where to forward the response.

Am not very good with networks but that's the idea but you can also look up a little more and be more certain, but the reason is because that IP stops at your router it doesn't go past it, meaning you can't use it out side the network

@edmondsylar
I understand now. I had to use whoer.net to get a public IP for it to work as expected.
Thank you very much. Well appreciated