I am a complete novice to PHP althoigh I have a programming background. I just want a simply peice of code to embed amongst my wordpress php page that detects the refering page and if its not say "www.abc.xom/page" then it redirects them to "www.xyz.com"
If not come from specific URL redirect to other URL
- Edited
You can inspect $_SERVER['HTTP_REFERER']
, though it could produce false negatives/positives (as per http://php.net/manual/en/reserved.variables.server.php):
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.
You might need some parsing/pattern-matching to handle cases when the sub-domain is/isn't there, slashes after or not after that page name, etc.?
If the desired referrer is a page/host you also have control of, there might be better options than HTTP_REFERER, but that's about all you get otherwise, as Nog suggests.
- Edited
After a quick use of the Wordpress site's search function I found
https://codex.wordpress.org/Function_Reference/wp_get_referer
which has an example of redirecting to different pages based on whether or not the page referrer was given or not. That might help.