How to use request.getHeader("Referer")

Mujahid picture Mujahid · Apr 4, 2011 · Viewed 36.2k times · Source

In my current project, I have a shopping cart integrated with the main site. Now I have to create some mini sites to display the data retrieved from main site. When the user click buy now button in mini site, it should redirect to the main shopping cart. But when user click the Continue shopping button, that should be send back to the mini site page where he was browsing. Both sites will be in 2 different domain names. Can I send him back to the page where he was browsing us?

request.getHeader("Referer")

This will be 2 different web apps so will the request.getHeader("Referer") help to send him back to the page where he was browsing.

Please send me some suggestions.

Answer

axtavt picture axtavt · Apr 4, 2011

You shouldn't rely on Referer for the logic of your application, since sending Referer can be blocked by firewalls or browser configuration.

Consider passing return URL as a parameter instead: http://mainsite.com/shoppingCart?returnTo=http%3a%2f%2fminisite.com%2foriginalPage.

Also make sure that returnTo points to your site to avoid possible security problems.