I am having one scenarion where I am checking if user submitted URL is already present in database or not. My concern is user can submit the same url in different format. e.g. URL http://mysite.com/rahul/palake/?&test=1 & URL http://www.mysite.com/rahul/palake/?&test=1 should be considered one and the same. If I have already stored the url as http://mysite.com/rahul/palake/?&test=1 in my database then searching for url http://www.mysite.com/rahul/palake/?&test=1 in database should give me message as url already existing. For this I am using following code, the following code works for me, I want to make sure it covers all possible scenarios? or this code can be improvised?
$url="http://dev.mysite.com/rahul/palake/?&test=1";
$parse_url=parse_url($url);
//first check if www is present in url or not
if(!strstr($parse_url['host'],'www'))
{
$scheme=trim($parse_url['scheme']);
//assign default scheme as http if scheme is not defined
if( $scheme =='')
$scheme='http';
//create new url with 'www' embeded in it
$url1=str_replace($scheme."://",$scheme."://www.",$url);
//now $url1 should be like this http://www.mysite.com/rahul/palake/?&test=1
}
//so that $url && $url1 should be considered as one and the same
//i.e. mysite.com/rahul/palake/?&test=1 is equivalent to www.mysite.com/rahul/palake/?&test=1
//should also be equivalent to http://mysite.com/rahul/palake/?&test=1
//code to check url already exists in database goes here
//here I will be checking if table.url like $url or table.url like $url1
//if record found then return msg as url already exists