Welcome Guest, Not a member yet? Register   Sign In
Get real ip
#1

Hi
I try use
PHP Code:
    function get_user_ip() {

        
$ipaddress '';

        if (
getenv('HTTP_CLIENT_IP'))
            
$ipaddress getenv('HTTP_CLIENT_IP');
        else if(
getenv('HTTP_X_FORWARDED_FOR'))
            
$ipaddress getenv('HTTP_X_FORWARDED_FOR');
        else if(
getenv('HTTP_X_FORWARDED'))
            
$ipaddress getenv('HTTP_X_FORWARDED');
        else if(
getenv('HTTP_FORWARDED_FOR'))
            
$ipaddress getenv('HTTP_FORWARDED_FOR');
        else if(
getenv('HTTP_FORWARDED'))
           
$ipaddress getenv('HTTP_FORWARDED');
        else if(
getenv('REMOTE_ADDR'))
            
$ipaddress getenv('REMOTE_ADDR');
        else
            
$ipaddress 'UNKNOWN';

        if (
$ipaddress == '::1' || $ipaddress == 'localhost')
            
$ipaddress  =   '151.235.98.154';

        if (
strpos($ipaddress,',') !== FALSE) {
            
$ipaddress  =   explode($ipaddress)[0];
        }

        return 
$ipaddress;

    } 

But it get 159.69.37.104,159.69.37.14
But i need real ip
Please help me
Reply
#2

Have a look if the correct values appear in $_SERVER variable, anywhere.

Built in ip_address function was relatively good too - https://www.codeigniter.com/user_guide/l...ip_address

If you use more advanced set up, I remember our loadbalancer masking real IPs sometimes until sys admin changed config to pass real user IP when request was sent to different web server instances.
Reply
#3

Oh yes ip_address exist in codeigniter
Thanks
Reply




Theme © iAndrew 2016 - Forum software by © MyBB