87439/how-to-get-real-ip-from-visitor
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?
Hello @kartik,
Try this php code.
<?PHP function getUserIP() { // Get real visitor IP behind CloudFlare network if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) { $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"]; $_SERVER['HTTP_CLIENT_IP'] = $_SERVER["HTTP_CF_CONNECTING_IP"]; } $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; } return $ip; } $user_ip = getUserIP(); echo $user_ip; // Output IP address [Ex: 177.87.193.134]
Hope it helps!! Thank you!!
Hello, Here is a code sample of a good ...READ MORE
Hello @kartik, You can use the parse_url() and parse_str() for that. $parts = ...READ MORE
Hello @kartik, Set the name in the form ...READ MORE
Hello @kartik, You can fetch the value of ...READ MORE
Hey @kartik, First you have to go to ...READ MORE
Named route is used to give specific ...READ MORE
Hello, This is simple you just need to ...READ MORE
Hey @kartik, Named routing is another amazing feature of ...READ MORE
Hello @kartik, You could download a free GeoIP ...READ MORE
Hii @kartik, If you want the biggest image ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.