简体   繁体   中英

Get content page using visitor IP

How I can get content of web page using visitor IP? I can't do it by AJAX because the page is using CROSS-DOMAIN policy.

Thanks.

EDIT:

I have to get content of web page (HTML code) - http://vshare.io/d/f3c85be . You can see - on this web page is Download URL. This URL is generated for user's IP - every user has another download link. I need to get this link for every visitor. I can't get this URL using AJAX because this page is using CROSS-DOMAIN POLICY. I can't get this content using CURL because this URL will generated for IP of my server (not visitor IP) and exacly it won't work.

How I can get content of web page using visitor IP?

You don't need an IP to get a webpage.

You need the url to the page and you can use $ homepage = file_get_contents('http://www.example.com/'); echo $homepage;

Maybe I'm misunderstanding, maybe you're referring to the IP address being the url then you can do this

file_get_contents('http://192.168.1.1/content.html');`
echo `$homepage;`

You can use the function below to get their ip address. Don't use the short built in php function to get that, it won't always guarantee an IP address.

function getUserIP()
{
    $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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM