PHP: check which page the link is directed from

let's say that I have a page hit.phpon my website, and a link to this page is available on all \ many pages on the website ..

will say that I click <a href"hit.php">HIT</a>from any page .....

there is a way when it loads hit.php, I could know that the page this page was from.

means that if I click on the link hit.phpfrom 'index.php', I can check the load hit.phpthat the user moves here from index.php or any other page ...

I know that this can be set on the site by passing variables to the URL, for example, "hit.php? Pagename = index", but is there any other way

ps I know him crazy, but still :)

+3
source share
2 answers

$_SERVER['HTTP_REFERER']although it can be easily fooled or turned off.

+5
source

You can use the referent. In PHP, this is:

$_SERVER['HTTP_REFERER']

However, users can configure their browsers not to send them, or to spoof it. You must make sure that your code does not break if it is missing, or fake.

+1
source

Source: https://habr.com/ru/post/1776036/


All Articles