$_SERVER['HTTP_REFERER'] contains the link page. (And, yes, it is spelled incorrectly in PHP, because the HTTP specification is spelled incorrectly. See the picture.)
However, regardless of whether this header is sent, sometimes this is an option in the browser that some users have disabled, and indeed older browsers do not even support it, so depending on this it can be problematic.
Your code will have a better chance of working for more users if you simply add a hidden field to each of these 5 forms indicating which form.
source share