There's no reliable way to do it. Any answer that lists
$ENV{HTTP_REFERER} or something derived from it needs a disclaimer that states:
- It can be trivially faked
- It can be absent
- It can be wrong
So, beware the clueless attempting to give you clues.
-- Randal L. Schwartz, Perl hacker