Question

I am hosting one site at ccihosting.com and I tried to catch user IP with

$_SERVER['REMOTE_ADDR']

and I got IP of their server located in panama but not my IP. They told me it is because of shared hosting. But all webhostings have shared servers don't they ? And I got no problems of catching IP addresses. I would like to just know whther it is because of shared hosting or no.

Thanks

Était-ce utile?

La solution

IP address of your website differ on Shared Hosting. Many websites on Shared Hosting may have different DNS names but same IP addresses.

You will get a same IP address only when you are on Dedicated Hosting Server.

EDIT : Try this alternative code

<?php
function get_client_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';

    echo $ipaddress;
}

get_client_ip();
?>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top