E
E
EvgMul2017-04-07 11:54:06
PHP
EvgMul, 2017-04-07 11:54:06

How to correctly determine the user's ip?

Hello. I have a task to determine the address of the user who visited the site.
I found the database of cities and ip addresses and set it up for myself. But the trouble is that the ip address is determined strangely.
I define the ip address as follows: There are services that determine your ip address, and so, for example, my ip address is defined by my script as 192.168.8.121. This ip address is not in the database of my ranges, and services that determine the city by ip will not find anything. But the services that determine my ip give me a different address: 109.195.134.64. This address is already in the database and the city will be determined. Please tell me what I'm doing wrong and how to do it right? Thanks in advance to all who respond.
$ip = $_SERVER['REMOTE_ADDR'];

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Smithson, 2017-04-07
@EvgMul

Comrade, you urgently need to read about the "white" and "gray" ip addresses.

S
Saboteur, 2017-04-07
@saboteur_kiev

Apparently your site is running on your machine, and you yourself go to the local address.
And 109.195.134.64 is not the address of your machine, but of your router through which you access the Internet.
You need to spend an hour or two reading about the basic concepts of IP networks and routing.
Start here
https://en.wikipedia.org/wiki/%D0%A7%D0%B0%D1%81%D...

T
themedev, 2017-04-09
@thematdev

Read

Дорогой друг, прочитай всё про IP адреса. На это у тебя уйдет 1 час. И ты всё узнаешь.
Ты ламер!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question