Struggling to display accurate public IP address lookup results for new 'What is my IP' tool
Introduction: Hey everyone, I'm a complete newbie here on AdsVolt, just starting out with my first ever web tool: 'What is my IP Address'. It's a simple little utility, but I'm already running into some unexpected issues that I could really use some help with.
The Core Problem: The main issue is that my tool isn't consistently showing the user's actual public IP address. Sometimes it displays my server's internal IP (like an AWS private IP), or occasionally a proxy IP, instead of the client's true public IP for the IP address lookup. It's really frustrating because the whole point of the tool is to show *their* IP.
What I've Tried So Far: I've been trying various methods in PHP to fetch the IP. I started with
$_SERVER['REMOTE_ADDR'], which I thought would be straightforward. When that didn't work consistently, I looked into checking$_SERVER['HTTP_X_FORWARDED_FOR']and$_SERVER['HTTP_CF_CONNECTING_IP'](in case of Cloudflare), trying to prioritize them. I even tried a third-party API for IP address lookup, but that felt like overkill for such a basic tool and added latency.Expected vs. Actual Output: I expect my tool to show my actual public IP, for example,
203.0.113.42. But very often, especially when I test from different networks or behind certain proxies, I get something like172.31.X.X(an internal AWS IP) or another proxy's IP. Here's a simplified illustration of what I'm seeing:// Current output from my 'What is my IP Address' tool: Your IP Address: 172.31.X.X (Internal AWS IP or Proxy IP) Expected IP Address: 203.0.113.42 (My actual public IP)My Specific Questions:
What's the most reliable and efficient way to get a user's true public IP address in a PHP web tool?
Are there common server configurations (like Nginx or Apache proxying) that might be interfering with
REMOTE_ADDR, and if so, how can I account for them?Are there specific HTTP headers I should be checking in a particular order to ensure I'm getting the client's IP, even if they are behind a proxy or CDN?
Call for Help: Any guidance or tips on how to correctly implement this IP address lookup feature would be super helpful. Help a brother out please!
0 Answers
No answers yet.
Be the first to provide a helpful answer!