hi all noob to php and ive been trying to work this out for a bit.Hoping someone might be kind enough to help. If i have a website that has a 404 set up to redirect to another site. Is there a way of displaying the referer url and also main domain that the person was bounced from ? Ive tried this: $referer = $_SERVER['HTTP_REFERER']; $refererhome = $_SERVER['HTTP_HOST']; and then echo results etc but it doesnt seem to work ! I just get nothing for referer and referhome gives main url of site that script is on not where bounced from. Any ideas???? thanks
ok...so made a simple link on other url as suggested by ads2elp The script i direct too now showed the referring link $referer = $_SERVER['HTTP_REFERER']; as correct address from where it came. However still showed host $refererhome = $_SERVER['HTTP_HOST']; as server that script was running on and not site redirected from. So it appears in terms of a 404 there is no referring url?? is that right ? And still doest explain why host doesnt display from redirected site. confused....and thanks for your help.
HTTP_HOST is suppose to show the host it is coming from. You need to probably regex the referer to get the main domain name
aaah...so HTTP_HOST shows the host that the script is on not referring host? Any ideas how i do the regex then? thanks.
$referer = $_SERVER['HTTP_REFERER']; preg_match('@^(?:http://)?([^/]+)@i', $referer, $matches); $host = $matches[1]; echo $host; // or do something with it Code (markup):
atlantaazfinest THANK YOU ! That worked for the link and getting host ! Your a star.Rep added So now all i need to do is to be able to get referer from a 404 redirect.Is that impossible?
No problem if the 404 is directly redirecting to your script the header should have the referer in it. unless like stated before referer info is stripped at browser level
404 is directing straight to script.Do yo happen to know what browsers strip? And is there a way around it? or is there another way of passing referer so its not stripped?
No you can set browsers to strip or add add-ons ... so i dunno if there would be a list but you can in the 404 redirect add a GET variable to the redirect url this would make it alot easier on your script
if u have access to the 404 redirect probably something like header("Location: http://yourdomain.com/atyourscript.php?r=".$_SERVER['HTTP_HOST']); YOUR SCRIPT: $refererhost = $_GET['r'];