I'm using this PHP code to get a visitor's IP address:
<?php echo $_SERVER['REMOTE_ADDR']; ?>
But, I can't get the real IP address from visitors when they are using a proxy. Is there any way to get a visitor's IP address in this case?
I'm using this PHP code to get a visitor's IP address:
<?php echo $_SERVER['REMOTE_ADDR']; ?>
But, I can't get the real IP address from visitors when they are using a proxy. Is there any way to get a visitor's IP address in this case?
This is my approach:
How to use:
This is my function.
benefits :
Try this php code.
Proxies may send a
HTTP_X_FORWARDED_FOR
header but even that is optional.Also keep in mind that visitors may share IP addresses; University networks, large companies and third-world/low-budget ISPs tend to share IPs over many users.
Yes,
$_SERVER["HTTP_X_FORWARDED_FOR"]
is how I see my ip when under a proxy on my nginx server.But your best bet is to run
phpinfo()
on a page requested from under a proxy so you can look at all the availabe variables and see what is the one that carries your real ip.This is the most common technique I've seen:
Note that it does not guarantee it you will get always the correct user IP because there are many ways to hide it.