get ip in laravel 1

get ip in laravel

public function getUserIpAddr(){
       $ipaddress = '';
       if (isset($_SERVER['HTTP_CLIENT_IP']))
           $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
       else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
           $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
       else if(isset($_SERVER['HTTP_X_FORWARDED']))
           $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
       else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
           $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
       else if(isset($_SERVER['HTTP_FORWARDED']))
           $ipaddress = $_SERVER['HTTP_FORWARDED'];
       else if(isset($_SERVER['REMOTE_ADDR']))
           $ipaddress = $_SERVER['REMOTE_ADDR'];
       else
           $ipaddress = 'UNKNOWN';    
       return $ipaddress;
    }

Here is what the above code is Doing:
1. It’s checking if the user is using a proxy server.
2. If the user is using a proxy server, it’s checking if the user is using a proxy server that is forwarding the user’s IP address.
3. If the user is using a proxy server that is forwarding the user’s IP address, it’s checking if the user is using a proxy server that is forwarding the user’s IP address and the user’s IP address is in the HTTP_X_FORWARDED_FOR header.
4. If the user is using a proxy server that is forwarding the user’s IP address and the user’s IP address is in the HTTP_X_FORWARDED_FOR header, it’s checking if the user is using a proxy server that is forwarding the user’s IP address and the user’s IP address is in the HTTP_X_FORWARDED_FOR header and the user’s IP address is in the HTTP_X_FORWARDED header.
5. If the user is using a proxy server that is forwarding the user’s IP address and the user’s IP address is in the HTTP_X_FORWARDED_FOR header and the user’s IP address is in the HTTP_X_FORWARDED header, it’s checking if the user is using a proxy server that is forwarding the user’s IP address and the user’s IP address is in the HTTP_X_FORWARDED_FOR header and the user’s IP address is in the HTTP_X_FORWARDED header and the user’s IP address is in the HTTP_FORWARDED_FOR header.
6. If the user is using a proxy server that is forwarding the user’s IP address and the user’s IP address is in the HTTP_X_FORWARDED_FOR header and the user’s IP address is in the HTTP_X_FORWARDED header and the user’s IP address is in the HTTP_FORWARDED_FOR header, it’s checking if the user is using a proxy server that is forwarding the user’s IP address and the user’s IP address is in the HTTP_X_FORWARDED_FOR header and the user’s IP address is in the HTTP_X_FORWARDED header and the user’s IP address is in the HTTP_FORWARDED_FOR header and the user’s IP address is in the HTTP_FORWARDED header.
7. If the user is using a proxy server that is forwarding the user’s IP address and the user’s IP address is in the HTTP_X_FORWARDED_FOR header and the user’s IP address is in the HTTP_X_FORWARDED header and the user’s IP address is in the HTTP_FORWARDED_FOR header and the user’s IP address is in the HTTP_FORWARDED header, it’s checking if the user’s IP address is in the REMOTE_ADDR header.
8. If the user’s IP address is in the REMOTE_ADDR header, it’s returning the user’s IP address.
9. If the user’s IP address is not in the REMOTE_ADDR header, it’s returning the string “UNKNOWN”.

Similar Posts