tags:

views:

37

answers:

4

Take a look to this function please

function CheckHost()
{
    $url = parse_url($_SERVER['HTTP_REFERER']);
    $host = $url['host'];
    if($host == $_SERVER['SERVER_NAME'])
        return true;
    return false;
}

i saw it somewhere, but can't understand it's usage.

is it for security reasons, or what?(as i see, it just verify is the last request from the same server as the script)

Thanks for attention

+2  A: 

I suppose it's a simple check against cross-site request forgeries (CSRFs), or as others say, hotlinking. The PHP script calling this function would have to be executed on every HTTP request to the server in order to check for hotlinking, though.

BoltClock
A: 

it checks whether the referer is equal to the script location, basically its function is probably to prevent hotlinking

Christian Smorra
A: 

It looks like its checking to see that the referrer is the same host name as the request. This is probably used for something like preventing other sites from directly linking to images or other content.

GrandmasterB
A: 

This can be used for CSRF protection. The Referer will always be of a differnt domain and thus CheckHost() will return false.

Rook