Hello! I have a website about cosmetics where I want to offer specials for people who come to my website from specific sites. I have found something like that: <?php $referrer = $_SERVER['HTTP_REFERER']; if (preg_match("/specificwebsite.com/",$referrer)) { header('Location: http://www.mywebsite.com/1.html'); } else { header('Location: http://www.mywebsite.com/2.html'); }; ?> Code (markup): But this is REDIRECTING and its only for one referrer (I have them over 20), I need something that INCLUDE files, is it possible with $_SERVER['HTTP_REFERER']? Also it is possible to have these specific domains in external file like domains.txt so I do not have to edit every page on my website when I update that list? Anyone know script that can do that? Thank you for help, Evelin
You could make use of http://php.net/manual/en/language.types.array.php and check if the domainname is in the $_SERVER['HTTP_REFERER']; example: <?php $sites = array( "www.yourwebsite.com" => "1.html", "www.google.com" => "2.html", "www.bing.com" => "3.html", "www.mysite.org" => "4.html", "tweakers.net" => "5.html", "www.test.com" => "6.html" ); foreach ($sites AS $key => $location) { if (stripos($_SERVER['HTTP_REFERER'], $key) > 0) { header("Location: " . $location); exit; } } ?> PHP:
I have a script that should do what I want, it looks like this: <?php $x=$_SERVER['HTTP_REFERER']; $x1=str_ireplace("http://","",$x); $t=file_get_contents("sites.txt"); $arr=explode("\n",$t); if(!empty($x) && in_array($x1,$arr)) { include("file1.php"); } ?> PHP: Unfortunately when I added this to my website I got "Internal Server Error", anyone can tell me what is wrong with that code? Thank you, Evelin
$referer = str_ireplace('http://', '', $_SERVER['HTTP_REFERER']); $refListing = explode("\n", file_get_contents('sites.txt')); if(in_array($x1, $arr)) { include("file1.php"); } Code (markup): better way is to create a seperate PHP file with your list you want to use as referer check <?php /* array_referers.php */ $refererCheckArray = array( /* your list to all the 'files' */ 'yourwebsite.com' => 'file1.php', 'otherwebsite.com' => 'file2.php', 'google.com' => 'google.php', 'gfxpoll.com' => 'polls.php', 'etc' => 'etc.php' ); foreach ($refererCheckArray AS $url => $file) /* loop rech row in refererCheckArray key = value { if (stristr($_SERVER['HTTP_RERFERER'], $url)) // is the referer containing the url case insensetive { include($file); break; /* break foreach, no need to contine..*/ } } ?> Code (markup): and you can use this code as an include! *code not tested!*