是否可以使用PHP跟踪用户在网站上的导航? 如果是这样,怎么样?

On a website I'm making, I would like to know how a user landed on a particular page (say here.php). There could be two possible ways: by clicking the link on page1.php or the link on page2.php. How can I find out how the user reached, so that I can provide content according to that.

HTTP_REFERER

$_SERVER['HTTP_REFERER'] DOCs should give you page the user has arrived from:

The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

Using a session

If you want to track a users progress through your site then it would be easier/safer to set a session (session_start() DOCs) and use that to track them as they land on your pages.

You could include a snipped of code in for example the footer of each page where you save the refferring page( $_SERVER['HTTP_REFERER'] ), but also the current page. If you use the Session_id as a unique identifier for the visitor you are then able to see the history of each visitor.