문제

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

도움이 되었습니까?

해결책

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();
?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top