If you're running Apache, you could always do it the "safer" way and say:
$headers = getallheaders();
if ($headers["Referer"] == $valid_referer) {
// It's a good one!
} else {
// It's a bad one...
}
There must be other ways, but I personally find this more secure. Hope this helps 🙂