Doing this with preg_match
would not be the best option. I suggest you create a list of domains in the form of a string, convert it to array, and check if any array value is present in REFERER with strpos()
.
Creates a list of domains separated by commas:
$dominios = "dominio01.com, dominio02.com, dominio03.com";
Convert to array:
$doms_array = explode(',', $dominios);
With foreach
you will check if any items in the array are present in REFERER. I also created a $flag
with initial value false
. If it finds any occurrences, it will change to true
:
$flag = false;
foreach($doms_array as $keys){
if(strpos($_SERVER['HTTP_REFERER'], trim($keys))){
$flag = true;
break;
}
}
And if
would look like this:
<?php if (isset($_SERVER['HTTP_REFERER']) && $flag) { ?>
COM REFERENCIA
<?php } else{ ?>
SEM REFERENCIA
<?php }?>
Full Code:
<?php
$dominios = "dominio01.com, dominio02.com, dominio03.com";
$doms_array = explode(',', $dominios);
$flag = false;
foreach($doms_array as $keys){
if(strpos($_SERVER['HTTP_REFERER'], trim($keys))){
$flag = true;
break;
}
}
?>
<?php if (isset($_SERVER['HTTP_REFERER']) && $flag) { ?>
COM REFERENCIA
<?php } else{ ?>
SEM REFERENCIA
<?php }?>