检查列表上的推荐和打印警报

I'd like a code to check if the referrer URL of a visitor to my Website is registered on a list, so then it will give back one alert or another. I have tried this, but doesn't work, and it can just check if the visitor is coming from a specific URL, not checking a list as I want:

<?php
if (ref.match(/^https?:\/\/([^\/]+\.)?friendsite\.com(\/|$)/i)) {
  alert("You came from a friend Website");
  else { alert("You came from a non friendly Webstie");
}
?>
   if(!empty($_SERVER['HTTP_REFEREF'] ) {// if there is referer
       $host = parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); // parse site (remove page, protocol, etc
       if(in_array($host, array('site.com', 'friend.ru'))) {
           echo "<script>alert(\"etc\")</script>";
       }
   }