How can I detect the site the user came from before accessing mine in PHP?
echo $_SERVER['HTTP_REFERER'];
It's not entirely reliable and can be spoofed, but in general it will be populated with the URL that the user clicked to get to the script.