Jump to content

Domain Names


mpharo

Recommended Posts

I am writing a reporting tool for the open source project Dansguardian, right now I am taking a URL that a user has visited and need to compare it to a blacklist, which contains just domain names (i.e. - phpfreaks.com). I currently have some code which does this but it does not work for https URL's. Here is the code:

 

while($sql=mysql_fetch_array($select)) {

 

preg_match('@^(?:http://)?([^/]+)@i',

   $sql, $matches);

   $host = $matches[1];

 

echo "host is: $host\n";

 

preg_match('/[^.]+\.[^.]+$/', $host, $matches);

echo "domain name is: {$matches[0]}\n";

 

}

 

I then found the parse_url(); function and tried using that, but that dosent strip off the subdomains. It just returns the host.

 

Does anyone have a snippet or a modification they could suggest?

 

Thanks in advance...

Link to comment
Share on other sites

Try

 

<?php

while($sql=mysql_fetch_array($select)) {

preg_match('@^(?:http://|https://)?([^/]+)@i',
   $sql[url], $matches);
   $host = $matches[1];

echo "host is: $host\n";

preg_match('/[^.]+\.[^.]+$/', $host, $matches);
echo "domain name is: {$matches[0]}\n";

}

?>

 

their probably a better way

 

but i think that will work

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.