The referer (sic) header

The referer header, misspelt for historic reasons, indicates the link that "referred" the user to the page being requested. In some cases, the referral may be implicit (for example, a request for an embedded image within a page will generally send the URL of the parent page in many browsers).

The referrer string is most often used to gather statistics about traffic sources to help with site marketing or identifying new markets.

Remember that the referrer string contains the whole URL, so if you want to collect statistics per site, then you will need to perform the appropriate filtering of the URL.

Determining search terms

When the referrer is a search engine results page, many search engines also send the search terms entered by the user. For example:

http://www.google.com.au/search?hl=en&q=sidney+shopping

A simple regular expression will suffice to pull out the raw search term. This could then be used to present the user with a more appropriate use of the page, for example.

IP geolocation

In interesting use of the referer header is as an approximate form of geolocation: that is, guessing the country of a given client. See the separate page on IP location from the referrer string.


If you enjoy this Java programming article, please share with friends and colleagues. Follow the author on Twitter for the latest news and rants.

Editorial page content written by Neil Coffey. Copyright © Javamex UK 2021. All rights reserved.