How can I detect the site the user came from before accessing mine in PHP?
Try this:
$_SERVER['HTTP_REFERER']
For more information, please see HTTP referrer:
The referrer, or HTTP referrer—also known by the common misspelling referer that occurs as an HTTP header field—identifies, from the point of view of an internet webpage or resource, the address of the webpage (commonly the URL, the more generic URI or the i18n updated IRI) of the resource that links to it. By checking the referrer, the new page can see where the request came from.