What’s the best way to detect referrer?

The best way to check the referrer will depends of what are you trying to do. You can use wp_get_referer() or wp_get_original_referer(), but if you want to check the referer for security reasons you should definitely use other functions like check_admin_referer(), check_ajax_referer(), wp_referer_field() or other of the WordPress Nonces related functions.