How to compare domain names within two URLs
Posted: Tue Mar 04, 2008 10:50 am
I'm trying to compare two URLs to see if they come from the same domain name.
1) the urls can be unsecure or secure (http or https)
2) there may or may not be a host designation (www)
3) the host designations may be different (www, ns2, etc)
example input:
http://www.domain.com/somepage.html
https://www2.domain.com/anotherpage.html
results: same domain name
My current snip is quite primitive (only comparing strings):
Any help greatly appreciated.
1) the urls can be unsecure or secure (http or https)
2) there may or may not be a host designation (www)
3) the host designations may be different (www, ns2, etc)
example input:
http://www.domain.com/somepage.html
https://www2.domain.com/anotherpage.html
results: same domain name
My current snip is quite primitive (only comparing strings):
Code: Select all
function check($url1, $url2)
{
global $settings;
if(!stristr($url1, $url2))
return NOT_SAME_DOMAIN;
if (url_exists($url1))
{
$page = join("", file($url1));
if(stristr($page, $settings['url_option'])==false)
return NOT_FOUND. $url1;
}
else
return URL_NOT. $url1;
return false;
}