Closed Thread Icon

Topic awaiting preservation: PHP: Domain-based redirection via an array... (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=26479" title="Pages that link to Topic awaiting preservation: PHP: Domain-based redirection via an array... (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: PHP: Domain-based redirection via an array... <span class="small">(Page 1 of 1)</span>\

 
DaveFA
Bipolar (III) Inmate

From: USA
Insane since: Feb 2004

posted posted 08-18-2005 23:22

I'm trying to create a page that will redirect users from a few different sites to a different page, and I'm having some trouble making it work for more than one page. Basically, here's what works for one page:

Before the DOCTYPE declaration:

code:
<?php
	$comingFrom = $_SERVER['HTTP_REFERER'];
	$itWorked = "It worked, indeed!";
	$sitesArray = array("mydomain.com", "otherdomain1com", "otherdomain2.com");
?>



In the body:

code:
<?php 
if(substr_count($comingFrom, 'mydomain.com')) {
	echo $itWorked;
} else {
	echo $comingFrom;
}
 ?>



The $comingFrom variable is there just to confirm that it works (for now). Later on, I'll replace that with the code to redirect folks to the other page.

You'll notice there's an array declared up at the top. What I want to do is call that array in place of 'mydomain.com' in the "body code". My question is, how can I do that?

Thanks.

-----------------------------------
-Dave

Maker of stuff, user of things
-----------------------------------

zavaboy
Bipolar (III) Inmate

From: f(x)
Insane since: Jun 2004

posted posted 08-19-2005 02:28
code:
<?php 
$from = parse_url($comingFrom);
$pattern = '#('.str_replace('.','\.',implode('|',$sitesArray)).')$#i';
if(preg_match($pattern,$from[host])) {
	echo $itWorked;
} else {
	echo $comingFrom;
}
 ?>


Tested and works.



(Edited by zavaboy on 08-19-2005 02:33)

DaveFA
Bipolar (III) Inmate

From: USA
Insane since: Feb 2004

posted posted 08-19-2005 03:37

Thank you very much. Excellent work.

-----------------------------------
-Dave

Maker of stuff, user of things
-----------------------------------

« BackwardsOnwards »

Show Forum Drop Down Menu