Good question (and thanks for posting to the correct forum).
You can do this with moderate success using the server variable $_SERVER['HTTP_REFERER'], which contains the address of the page from which the user arrived. (Note that "REFERER" is missing an "R" .. this is a decade-old spelling quirk of the HTTP spec, or so I'm told).
Anyway, it's important to note that while this is useful, it's not foolproof. There are plenty of ways to spoof the referer/referrer, but unless you're handling sensitive data you probably don't need to worry about it.