Hi all,
Have written a basic script to connect to a search engine (in this case google) and retrieve how many sites are linked to or contain a specific URL.
Basically I run an expired domain list through this and it find URLs with existing traffic based on existing links.
This code works with Yahoo, MSN, Excite etc by changing the query string and the start and stop text, but google keeps giving me an error. I think its related to accepting a cookie - but really am not sure.
Any help would be appreciated.
<html>
<head>
<?
// This section of script connects to Google.com and returns the Avg. Traffic rank
function Google ($test_url)
{
$url = "http://www.google.com/search?as_lq=$test_url";
$unique_start = "of about <b>"; // Where to begin to grab
$unique_end = "</b>."; // Where to end the grab
$fd = fread(fopen("$url", "r"), 200000);
$start= strpos($fd, "$unique_start");
$finish= strpos($fd, "$unique_end");
$length= $finish-$start;
$code=Substr($fd, $start, $length);
return eregi_replace("of about <b>", "", $code);
}
// This section determines whether to show the input form or the results
if (empty($mass_urls) == TRUE)
// This section gets the domains to be searched for in a text box.
{
echo " <title>Google Site Popularity Checker</title>
<meta name='description' content=''>
<meta name='keywords' content=''>
</head>
<body>
<center><font face='verdana' size='2'><b>Google Site Popularity Checker</b></font><br><br>
<font face='verdana' size='1'>Best Expired Domains Source: <a href='https://secure.directnic.com/myaccount/register/expired.php' target='_blank'>DirectNic Expired Domains</a></font><br>
<br>
<form method='POST' action='".($PHP_SELF)."'>
<textarea rows='20' name='mass_urls' cols='50'
style='font-family: Verdana; font-size: 8pt'>
Google.com
aussiecelebs.com
amazon.com
bhp.com.au</textarea><br><br>
<input type='submit' value='Search Domains' name='B1'
style='font-family: Verdana; font-size: 8pt'>
</form>
</center>
";
}
// This section then takes the results from the text box, and puts them into an array and then displays them
else
{
$test_url = explode ("\r\n", $mass_urls);
echo "<title>Finished Query</title>
<meta name='description' content=''>
<meta name='keywords' content=''>
</head>
<body>";
echo "<p><font face='verdana' size='2'><b>Results Page (The bigger the number the better)</b><font></p>";
echo "<p><font face='verdana' size='-1'>Domains checked: <b>".count($test_url)."</b><font></p>";
foreach($test_url as $url)
{
// This checks that this url isn't a empty string:
// if it is we skip it. =)
if($url == "")
continue;
// Get the number of links.
$numLinks = Google($url);
// If the number of links is more than 0 print it.
if($numLinks > 100)
{
echo "<font face='verdana' size='-1'>The domain: <a href='http://www.$url' target='_blank'>$url</a> has: $numLinks links <b>*****</b><br>";
}
elseif($numLinks > 50)
{
echo "<font face='verdana' size='-1'>The domain: <a href='http://www.$url' target='_blank'>$url</a> has: $numLinks links <b>****</b></font><br>";
}
elseif($numLinks > 20)
{
echo "<font face='verdana' size='-1'>The domain: <a href='http://www.$url' target='_blank'>$url</a> has: $numLinks links <b>***</b></font><br>";
}
elseif($numLinks > 10)
{
echo "<font face='verdana' size='-1'>The domain: <a href='http://www.$url' target='_blank'>$url</a> has: $numLinks links <b>**</b></font><br>";
}
elseif($numLinks > 5)
{
echo "<font face='verdana' size='-1'>The domain: <a href='http://www.$url' target='_blank'>$url</a> has: $numLinks links <b>*</b></font><br>";
}
elseif($numLinks > 1)
{
echo "<font face='verdana' size='-1'>The domain: <a href='http://www.$url' target='_blank'>$url</a> has: $numLinks links </font><br>";
}
}
// This bit allows you to return to the original page and run the script again.
echo "<p><font face='verdana' size='-1'><a href=".$PHP_SELF.">Search Again</a><font></p>";
}
?>
</body>
</html>
Error it throws up is:
Results Page (The bigger the number the better)
Domains checked: 1
Warning: fopen("http://www.google.com/search?as_lq=Google.com", "r") - Success in /usr/local/psa/home/vhosts/phphacks.com/httpdocs/phPopularity_google.php on line 15
Warning: fread(): supplied argument is not a valid File-Handle resource in /usr/local/psa/home/vhosts/phphacks.com/httpdocs/phPopularity_google.php on line 15
Search Again