-1

Before you say it's a duplicate, I hereby state that i've tried everything on this site and it hasn't worked.

My problem is, i'm trying to get my site's visitor's IP adress to keep a log of who's accessing it, however, when I tested it with two different devices using the same internet connection, the IP is returning the same for the two.

When I tried with a device using 4G connection, it did show'd me a different IP. These IP's are varying from 9 to 12 charachters in length.

My question is: Are these the "connection's IP"? How do I get the specific device IP?

Current code used to get the IP:

$ip = getenv('HTTP_CLIENT_IP')?:
getenv('HTTP_X_FORWARDED_FOR')?:
getenv('HTTP_X_FORWARDED')?:
getenv('HTTP_FORWARDED_FOR')?:
getenv('HTTP_FORWARDED')?:
getenv('REMOTE_ADDR');

EDIT: This code is being run in the header.php file, wich is file being included from the index.php (main file).

Ravi Mattar
  • 179
  • 1
  • 12
  • 3
    Have you ever heard the term "NAT"? Your approach to identify users by their IP address simply does not work. – arkascha Jun 09 '18 at 13:10
  • I haven't, please explain. – Ravi Mattar Jun 09 '18 at 13:11
  • 3
    When using 2 devices (laptop, desktop) connected through the same router to the internet you will get the same IP address - the IP address of the router. Some companies use gateways, so 100's if not 1000's of people may appear to have the same IP address, sometimes the same person may connect from the same computer and have multiple different IP addresses. – Nigel Ren Jun 09 '18 at 13:11
  • In addition I would suggest that you simply use google and learn about network topologies. – arkascha Jun 09 '18 at 13:12
  • So how do I distinguish these devices? Is it even possible? – Ravi Mattar Jun 09 '18 at 13:14
  • Yes, I have tried it and it doesn't work. – Ravi Mattar Jun 09 '18 at 13:27
  • 1
    "*So how do I distinguish these devices? Is it even possible?*" ... from a webserver standpoint? and not reverse-hacking through routers to a users machine? .... I'd venture a 'no'. – IncredibleHat Jun 09 '18 at 13:44

1 Answers1

1

When using REMOTE_ADDR, you are getting that users public IP address, hence why you get the same for 2 devices on the same network. What you could do is set a cookie to state if they've been on your website. Then, when a user visits your website, check for the cookie, and if they don't have it, then you have another unique hit. If they do have that cookie, ignore it.

I hope this is helpful. If not, just DM me