Hi everyone
Having issues with ip address . Every time it gives me very false ips . Here is php code $client = $_SERVER['HTTP_CLIENT_IP']; $forward = $_SERVER['HTTP_X_FORWARDED_FOR']; $remote = $_SERVER['REMOTE_ADDR']; if (filter_var($client, FILTER_VALIDATE_IP)) $ip = $client; elseif (filter_var($forward, FILTER_VALIDATE_IP)) $ip = $forward; else $ip = $remote; echo '<script>console.log("'.$ip.'")</script>';
What’s the problem ? is there anyway to solve it ?
What do you mean by false IPs? Which IP addresses do you see instead of the actual IP (and which of the three $_SERVER you check from have this invalid IP)? And do you have this example code uploaded somewhere so we can check what it returns for us?
Check the console http://yoursoft.ga/page.php?id=5
Saying false IPs i mean that i refresh page i get ip like 162.158.159.21 , then i refresh and get
162.158.158.12 . And this happens everytime .
Thanks for sharing the additional information. I see what the issue is here.
The IP addresses you’re seeing are IP address from Cloudflare. That’s because you’re using Cloudflare on your domain name. This means that your browser connects to Cloudflare’s servers, and Cloudflare connects to your hosting account. Since, from our server’s perspective (and by extension, your code), Cloudflare is the party connection to our servers, you see Cloudflare’s IP instead of your own.
Fortunately, Cloudflare does send the IP address you are connecting from as well. Simply check the value of $_SERVER['HTTP_CF_CONNECTING_IP'] to get the IP address sent to you by Cloudflare.
I’m still waiting on judges to say something about things like access logs and rate limits. Basically every server in the world collects IP and temporarily stores addresses just to provide basic network security.