How to detect the site a user came from before mine in PHP?

前端 未结 6 1958
温柔的废话
温柔的废话 2020-12-07 02:38

How can I detect the site the user came from before accessing mine in PHP?

6条回答
  •  孤街浪徒
    2020-12-07 02:53

    As @Andrew Hare states in his answer, getting the value of the HTTP_REFERRER server value (which is a header that is sent as part of the HTTP request) will tell you the site that the browser was last on.

    What should be noted, however, is that it is completely possible that this header/server variable will have no value, for a number of legitimate reasons, some being:

    • The user typed in the URL to the site in the same window
    • The user opened a bookmark in the same window
    • The user just opened the browser and did one of the things above

    All of the above are really variations on the same thing, a case where the same browser window is used for going to another site, but wasn't prompted through clicking the on a link in a document which lead them there, a redirect, or some other action prompted by the page in the history before yours.

提交回复
热议问题