How to check similar websites by php code

Authors: CodeToday | PHP Code | Views: 432 | Posted: 07 AM: 09/09/2017

How to check similar websites by php codeGoogle search provides many free tools for checking the status of the website such as check the backlinks of a website, check similar websites, check the index of a website on google ... Here I will guide how to check similar websites with the website need to check

To check Similar Websites on google you need to use url query:
https://www.google.com/search?num=20&q=related:{domain need to check}


HTML

<form action="" method="post" class="form-horizontal">
<div class="form-group">
<input type="text" name="domain" id="domain" value="<?=$_POST['domain']?>" class="form-control" placeholder = "Enter domain here ..." required/>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-info">Check Similar Webs</button>
</div>
</form>

After click submit form, the domain name to check will be send to this url

https://www.google.com/search?num=20&q=related:$_POST['domain']

Full PHP Source Code

<?
if(isset($_POST['submit'])){

$url       = 'https://www.google.com/search?num=20&q=related:'.$_POST['domain'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_HTTPGET, 1 );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION , 1 );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION , 1 );
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_REFERER, $ref );
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);     
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$html = curl_exec($ch);
curl_close($ch);

$regexp    = "<as[^>]*href=("??)([^" >]*?)1[^>]*>(.*)</a>";
if(preg_match_all("/$regexp/siU", $html, $matches, PREG_SET_ORDER)) {

	foreach($matches as $match) {  
		if(filter_var($match[2], FILTER_VALIDATE_URL)) {
			if(stristr($match[2],'google')    == false &&
			   stristr($match[2],'search?q=') == false) {	
				 $urlLink[] = $match[2];   		 
			}		
		}
	}
}
print_r($urlLink);
}
?>

See Also: How to check backlinks of a website

Note: Searches from google will have a limited number of queries so you need to consider when attaching this tool to your website
If you have any questions, please leave a message below