This is the spam code I'm using:
if (strpos($SERVER['HTTP_REFERER'], $SERVER['HTTP_HOST'])>7 ||
!strpos($SERVER['HTTP_REFERER'], $SERVER['HTTP_HOST']))
die("Bad referer");
I'm not sure how safe it is. I have used other code that did specify the exact URL but found problems compensating for appended query strings. This one seems to work best.