User_agent library: robuster detection in is_referral()

Previous method was broken, but anyway I've replaced it with a robuster one, which avoid potential false positives.

Supersedes PR #2539