HTTP_REFERER does not exists sometimes. Check if it does.