When developing web programs, sometimes we need to get the page from which the user is connected. This is where referer is used.
It is an http protocol, so any language that can develop web programs can be implemented, such as jsp (the first choice for SUN enterprise-level applications) is:
request. getHeader("referer");
php(as the current mainstream development language) is $_SERVER[HTTP_REFERER]. I won’t give other examples (actually I don’t know other languages).
Then what can it be used for? Let me give you two examples:
1. To prevent illegal connections. For example, I am a website for downloading software. On the download page, I first use the referer to determine whether the previous page is my own website. If not, it means someone has stolen the connection. your download address.
2. For the security of e-commerce websites, I use referer on the page where I submit important information such as credit card to determine whether the previous page is my own website. If not, it may be a form written by a hacker. Submit, in order to skip the verification of javascript in your previous page.
Notes on using referer:
If I directly enter the page with referer in the browser, the return is null (jsp(the first choice for SUN enterprise applications)), that is to say, the referer will only have content if you click on the link from another page to this page.
I did an experiment. For example, my referer code is in a.jsp(the first choice for SUN enterprise applications), and its previous page is b.htm, c.htm It is a page with an iframe, which embeds a.jsp(the first choice for SUN enterprise-level applications) in the iframe. I enter the address of b.htm in the browser, and then click to connect to c.htm. The displayed result is b.htm. If I directly enter c.htm in the browser, the displayed result is c.htm