How to determine the user's ip?

Hello. My task is to determine the address of the user who visited the site.
Base cities and the ip addresses I found and customized. But the trouble is that the ip address is determined strange.
The Ip address I define in the following way:
$ip = $_SERVER['REMOTE_ADDR'];

There are services that determine your ip address, so for example my ip address my script is defined as 192.168.8.121. This ip address at the base of my bands there, and the services that define the city by ip won't find anything.
But defining my ip, give me another address: 109.195.134.64. This address is already in the database will be determined.
Please tell me what I'm doing wrong and how to do it properly?
Thanks in advance to all responded.
June 27th 19 at 15:36
3 answers
June 27th 19 at 15:38
Solution
Tovarisch, you have to read about "white" and "gray" ip addresses.
Thanks for the tip) - Wilhelm_Marquardt commented on June 27th 19 at 15:41
June 27th 19 at 15:40
Perhaps you have a website turns on your machine, and you do go to a local address.
And 109.195.134.64, this address is not your machine and your router, through which you go to the Internet.

You need to spend an hour or two, and read about the basic concept of IP networks and routing.
Start here
https://ru.wikipedia.org/wiki/%D0%A7%D0%B0%D1%81%D...
The website's not on my machine, but thanks for the advice, I esteem mandatory.
If you're interested, the problem was that nginx has replaced the headers with their ip addresses. Adjusted the nginx config and it worked. - Wilhelm_Marquardt commented on June 27th 19 at 15:43
June 27th 19 at 15:42
To read

Dear friend, read all about IP addresses. It will take you 1 hour. And you know.
Zabombit

You LAMER!
Well, there are people like you, who are in the world already know at birth and help us, stupid LAMER. - Wilhelm_Marquardt commented on June 27th 19 at 15:45
: Well, in principle thanks. - Wilhelm_Marquardt commented on June 27th 19 at 15:48

Find more questions by tags GeolocationProgrammingPHP