A couple of years ago, someone helped me with the code for an http referrer wild card. This was the solution:

$regex = '#^http://(www\.)?mydomain.com/checkout.html#'; 
if(!preg_match($regex, $_SERVER['HTTP_REFERER'])) 
{ 
   header('Location: forbidden.html'); 
   exit; 
} 

The full thread is here: http://phpbuilder.com/board/showthread.php?t=10355225

Now this works great, but how can I edit this so that the domain can be either .com or .co.uk?

    OK, so this seesm to work:

    $regex ='#^http://(www\.)?domain.com/checkout.html#'; 
    $regex = '#^http://(www\.)?domain.co.uk/checkout.html#'; 
    foreach ($regex as $refererKey => $refererValue) {
    if(!preg_match($regex, $_SERVER['HTTP_REFERER'])) 
    { 
       header('Location: forbidden.html'); 
       exit; 
    } 
    }

    Is there a better way to do it?

      Replace

      com

      with:
      code[/code]or slightly obfuscated:

      co(?:m|\.uk)

      Also note that the '.' has special meaning in regular expressions in that it matches any character. Thus, "checkout.html" will actually match "checkoutX.html" or "checkoutYhtml" or.. etc. If you want a literal period to appear in the pattern, you have to escape it (as I have done above).

        Write a Reply...