+2  A: 

You can use the HTTP_REFERER header.

<?php

$allowed_domains = array(
        'a-good-domain.com',
        'another-nice-one.org',
        );

$allowed = false;
foreach ($allowed_domains as $a) {
    if (preg_match("@https?://$a/.*@", $_SERVER['HTTP_REFERER'])) {
        $allowed = true;
    } 
}

if ($allowed) 
    echo "Nice domain";
else
    echo "Ugly domain";
Johan
You should really use a hash for this. No need to loop over `$allowed_domains` that way.
friedo
Awesome! That works perfectly. :)
PaulAdamDavis