Home  Servlets  Servlet hosting  Servlets intro  Sessions  Cookies  HTTP headers  Status codes  Keep-alive


Threads Database Profiling Regular expressions Random numbers Compression Exceptions C Equivalents in Java
 Comment on this article  List of Java topics

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.


Written by Neil Coffey. Copyright © Javamex UK 2008. All rights reserved.