Jump to content

If authorized domain do 1 action, if not do another?


Mike Solstice

Recommended Posts

Ok, basically I'm wanting to make a generic licensing system that will check the subdomain the php file is loaded on & if the root domain is authorized, load. If not display error or do some other action.

 

I've tried:

$address = $_SERVER['SERVER_NAME']; 
$address = str_replace('www.', '', $hostname); 
if (preg_match('{^http://[\w\.]*google.com/}i', $address))
{
else {
echo "fail"; 
}

 

Also tried a more complicated script I found on Google

$address = $_SERVER['SERVER_NAME']; 
$address = str_replace('www.', '', $hostname); 

if (get_domain($address) == "google.com") {
  print "Yes.";
}

function get_domain($url)
{
    $pieces = parse_url($url);
    $domain = isset($pieces['host']) ? $pieces['host'] : '';
    if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {
        return $regs['domain'];
    }
    return false;
}

 

Anyone have any ideas?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.