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. For example, in jsp it is:
request.getHeader("referer");
in php it is $_SERVER['HTTP_REFERER']. I won’t give other examples (actually I don’t know other languages).
So what can it be used for? Let me give you two examples:
1. Prevent stolen 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 that someone has stolen your download address.
2. The security of e-commerce websites. On the page where I submit important information such as credit cards, I use referer to determine whether the previous page is my own website. If not, the hacker may have used a form written by himself to submit it in order to skip it. For verification purposes of the javascript on your previous page.
Notes on using referer:
If I directly enter the page with the referer in the browser, the return value is null (jsp), which means that 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, and its previous page is b.htm. C.htm is a page with an iframe, and it embeds a.jsp 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.