Code:
if (!empty($_SERVER['REFERER']) && strpos($_SERVER['REFERER'], 'domain.com') === false)
{
exit;
} Since browsers can fake referrer headers aside from some serious work there's no real way to create restrictions, but that will at least deal with those not deliberately trying to get around it.