javascript redirect based on referral url

BigWill

A Living Legend.
Oct 14, 2007
4,019
107
0
In Hotels
I used to have this code, I tried recoding it myself but I suck, google also sucks

Anyone have this code handy?

If ref url = aol.com then newurl=google.com
 


if (document.referrer != "") {
var referringURL = document.referrer;
var local = referringURL.substring(referringURL.indexOf("?"), referringURL.length);
location.href = "http://page.com/login" + local;
}

thats close
 
Code:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var refarray = new Array();
refarray['referringdomain.com'] = "http://www.google.com";
refarray['referringdomain2.com'] = "http://www.google.co.uk";
refarray['referringdomain3.com'] = "http://www.google.it";
for (var i in refarray) {
if (document.referrer.indexOf(i) != -1) window.location.replace(refarray[i]);
}
// End -->
</script>
In case you were still looking...
 
Code:
<?php
$referrer = $_SERVER['HTTP_REFERER'];
if (preg_match("/subdomain\.domain\.com/",$referrer)) {
      header('Location: http://www.redirect-here.com/');
} else {
      header('');
};
?>

place this at the very top before your opening HTML tags

Make sure to use \ before periods or PHP will not understand it..

Also make sure PHP is enabled if this does not work.
 
I can't put it in the head tags this is going into the top of my prosper script that about 30 people are pulling. I used to have a good one but I removed it like a dumbass.

So its pulling from a <script=blah.php></script>
 
I wish I could help you on that one Will, my coding kung-fu isn't that strong unfortunately...in fact this is a code snippet I've used myself one time that I found from somewhere else.
 
This is basically the same as edwin's code. It works. In IE and FF... maybe you have referrers disabled in your browser if it's not working for you.
Code:
<script type="text/javascript">
var baddomain = 'aol.com';
var redir = 'http://www.google.com/';
if(document.referrer.indexOf(baddomain)!=-1) {
	location.replace(redir);
}
</script>