Hi, Does anyone know how to do a php redirect based on referrer? E.g.: someone comes from outsidesite.com to mysite.com, but I want to redirect them to mysite1.com. Thanks, Dave
Try: Havn't tested it just knocked it together, but it should direct referrers from outsidesite.com to mysite1.com and all other referrers to plain mysite.com
you can also try JS redirect... just another option: <script language="JavaScript"><!-- if (document.referrer.indexOf('outsidesite.com') > -1) location.href='http://mysite1.com'; else location.href='http://mysite.com'; //--></script>
For the PHP solution, what would the syntax be to search for a substring within the referer? In other words, any referer with "dog" in the url gets redirected to www.dogtrainingaffiliate.com and any referer with "work_from_home" gets redirected to www.wfhaffiliate.com, etc., else redirect to a page within my site.
You coud do a search on "PHP regular expressions" and probably find a solution. I use PHP on occassion, but I'm not very fluent in regualr expressions. I grabbed this link real quick to help guide you... http://www.regular-expressions.info/php.html Quoted from this site: preg_match (string pattern, string subject [, array groups]) returns TRUE if the regular expression pattern matches the subject string or part of the subject string.
<? $referrer = $_SERVER['HTTP_REFERER']; if (preg_match("/outsidesite.com/",$referrer)) { header('Location: http://www.mysite1.com'); } else { header('Location: http://www.mysite.com'); }; ?> If I want to match a LIST OF SITES, insted of "outsidesite.com" How can I work with a txt list of sites: "mysites.txt" instead of only one site: "outsidesite.com" <? $referrer = $_SERVER['HTTP_REFERER']; if (preg_match("(HERE A TXT WITH A LIST OF SITES",$referrer)) { header('Location: http://www.mysite1.com'); } else { header('Location: ht*tp://www.mysite.com'); }; ?> Anyone knows how to do it?