in reply to can't get $ENV{HTTP_REFERER}
IIRC, HTTP_REFERER can be spoofed and sometimes it doesn't get set, therefore is unreliable.
anyway, did you use $ENV{HTTP_REFERER} and it didn't work? where's the code?