Check referer before using it to avoid undef index-notices in the logs