I have a domain pointer (eg. www.example.com) to a second domain (eg. www.example.es) and I would like to know from which domain I come from. Is it possible to do it with PHP?
Asked
Active
Viewed 389 times
0
-
Had you read about HTTP_REFERER? – Viacheslav Kondratiuk Jan 03 '13 at 11:23
-
Doesn't it only has to be with the previous url visited? – jprog Jan 03 '13 at 11:36
-
In a 100% reliable way, probably not. But it depends exactly what you mean by "domain pointer". HTTP redirect, CNAME alias, vhost alias or what? – DaveRandom Jan 03 '13 at 11:36
-
It is a DNS redirection made from the control panel of my host, it has an option to create as an alias, but I didn't check that option... – jprog Jan 03 '13 at 11:40
2 Answers
0
Try this $_SERVER["HTTP_REFERER"];

Vassilis Barzokas
- 3,105
- 2
- 26
- 41
-
If I print the $_SERVER variable, it doesn't return any HTTP_REFERER parameter, as the browser doesn't come from a previous url... (wich is the usage I've found for that parameter)... – jprog Jan 03 '13 at 11:29
-
Then your answer is here http://stackoverflow.com/questions/4043196/get-http-referrer-on-redirection So, you cant. – Vassilis Barzokas Jan 03 '13 at 11:40
0
Assuming that by a "domain pointer" you mean a DNS CNAME record pointing from one domain name to another, then to know which of the two domain names was actually used to access the site, look in:
$server = $_SERVER["SERVER_NAME"];

Alnitak
- 334,560
- 70
- 407
- 495
-
Thanks, but in my case $_SERVER["SERVER_NAME"] returns always the "redirected" domain, not the domain where I come from... – jprog Jan 03 '13 at 11:34
-
@jpris then you need to explain how this redirection is being done. If it's with an HTTP 30x style redirection then AFAIK you can't tell what the original domain name was unless the redirecting server adds an additional header (or URI parameter) to tell you what the original domain name was. – Alnitak Jan 03 '13 at 11:44
-
Finally I've found the problem. Your answer is right but my pointer settings where wrong, I had to check it (when I created it) to create it as an alias. Without doing that, it always returned the domain it pointed to. – jprog Jan 03 '13 at 12:01