Link Popularity Checker

Maljonic

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,297
I want to make something like this: http://www.1-web-site-search-engine-optimization.com/link-popularity-check.php but I can't figure out how it works; is it because the script for the form is somewhere else? Is there a way to see the script they are using for this form or, even better, would it be easy enough to write a script so that the form works? If someone can help that would be great; I have started learning javascript, bought a book and everything, but this is a bit beyond me at the moment as I'm only a beginner. :)
 

Maljonic

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,297
Okay I'd like someone to help me with a php script for this, I know it can't be very difficult but I'm still not sure exactly how to write it at the moment - just a simple form where you enter a domain name in a box and it calls the php script to run 'link:http://www.mydomain.com' in Google, Yahoo, Altavista etc, or whatever the individual search engines are using for link checks, @mydomain.com or linkurl:mydomain.com and so on - then display the results in a table using mysql? :)

edit: I just want to say that it doesn't really matter that the results don't necessarily mean a lot, I just want to know how to do it as part of my PHP learning experience. :)
 

MYstIC G

Official Licensed Lump of Coal™ Distributor
Staff member
Moderator
FH Subscriber
Joined
Dec 22, 2003
Messages
12,362
Code:
javascript:location.href='http://www.google.com/search?q='+document.location.href;
Use that as a bookmark in Firefox it'll search in google for the URL you've input.
 

Maljonic

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,297
Sorry, I meant I want to put a form that does this on a website. :)
 

JingleBells

FH is my second home
Joined
Mar 25, 2004
Messages
2,224
Try (done using JS):
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Google Form</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function submitGoogleForm() {
	//this takes your submitted value, and adds "link:" to it
	var adValue = "link:"+document.getElementById("address").value;
	//Sets the hidden field q to equal adValue
	document.getElementById("q").value = adValue;
}
</script>
</head>
<body>
<!-- Change the action for other search sites //-->
<form id="googleForm" onsubmit="submitGoogleForm()" method="get" action="http://www.google.co.uk/search">
<p><input type="hidden" id="q" name="q" value=""></p>
<p>Enter an URL<input type="text" id="address" value=""></p>
<p><input type="submit" value="Submit"></p>
</form>
</body>
</html>
 

JingleBells

FH is my second home
Joined
Mar 25, 2004
Messages
2,224
Or in PHP:
Code:
<?php
if(isset($_GET["q"])) {
$query = $_GET["q"];
//Alter this for whatever query you want
$google = "http://www.google.co.uk/search?q=link%3A";
header("Location: $google$query");
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Google Form</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form id="googleForm" method="get" action="google.php">
<p>Enter an URL<input type="text" name="q" value=""></p>
<p><input type="submit" value="Submit"></p>
</form>
</body>
</html>
Test it here: http://www.pete-b.co.uk/google.php
 

Maljonic

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,297
Thanks JingleBells, that's the sort of thing I was talking about; how easy would it be to add searches, say for 3 different search engines, and print the results onto another page on your site - I mean the number of results not the actual list that appears in Google etc. Like when I enter www.maljonicsdreams.com into the two you made it says there are 222 results, so could it be done so that the results page says Google = 222 with the 222 being a link to the results that the current form of yours displays?

Thanks for what you did so far though, it already gives me a much better idea of how things work. :)
 

phlash

Fledgling Freddie
Joined
Dec 24, 2003
Messages
195
Ummn. You are trying to create a metasearch tool (like eg:dogpile), that counts hits in other search engines but doesn't display the results..

I think this will need either an API for each search engine (eg: GoogleAPI webservice), or you will have to parse the returned HTML and pull out the number(s) you want. The problem with parsing the HTML is that it can change at any time and your parser will fail :(

Perhaps it would be easier to just open each search result page in a browser frame for the user to parse by eye?
 

Maljonic

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,297
I'm not trying to create a meta search tool, at least I'm pretty sure I'm not, I just want to know how to get a simple version of something like this http://www.1-web-site-search-engine-optimization.com/link-popularity-check.php or this http://www.curve2.com/popularity-report.php to check how may links to a given site are registered with a given search engine.

It doesn't really matter what it checks for, doesn't have to be links, it could be pages with the allinurl: or site: command - I just want to know how to do it. :)
 

Maljonic

Can't get enough of FH
Joined
Dec 22, 2003
Messages
1,297
I found this free script after a lot of searching; it didn't work properly as it was so I had to change some minor details:

Code:
<?php
function fetch($source, $start, $smlen, $stop, $fail) {
	$data = @implode('', @file($source));
	$data = strip_tags($data);
	$data = strtolower($data);
	$data = str_replace("\n", '', $data);
	$data = str_replace("\r", '', $data);
	
	if(substr_count($data, $fail)) {
		return 0;
	} else {
		$data = substr($data, strpos($data, $start)+$smlen);
		$data = substr($data, 0, strpos($data, $stop));
		return trim($data);
	}
}

if($_POST[submit]) {
	$data = array();
	
	$target = trim(eregi_replace('http://', '', $_POST[target])); 
	
	// check Google
	$source = 'http://www.google.com/search?hl=en&lr=&ie=UTF-8&q=link%3A'.$target;
	$data['Google'] = array(fetch($source, 'of about', 9, 'linking', 'did not match any documents'), $source);
	
	// check MSN Search
	$source = 'http://search.msn.com/results.aspx?FORM=MSNH&srch_type=0&q=link%3A'.$target;
	$data['MSN Search'] = array(fetch($source, 'web results1-', 18, 'containing', "couldn't find any sites containing"), $source);
	
	// check Yahoo!
	$source = 'http://search.yahoo.com/search?p=linkdomain%3A'.$target.'&sm=Yahoo%21+Search&fr=FP-tab-web-t&toggle=1';
	$data['Yahoo!'] = array(fetch($source, 'of about', 9, 'for', "we didn't find any web pages"), $source);
	
	// check AlltheWeb
	$source = 'http://www.alltheweb.com/search?cat=web&cs=utf8&q=link%3A'.$target.'&rys=0&_sb_lang=pref';
	$data['AlltheWeb'] = array(fetch($source, 'audio1 -', 14, 'results', "no web pagesfound that match your query"), $source);
	
	// check HotBot
	$source = 'http://www.hotbot.com/default.asp?query=link%3A'.$target.'&ps=&loc=searchbox&tab=web&provKey=Inktomi&prov=HotBot';
	$data['HotBot'] = array(fetch($source, 'results 1 -', 17, ')', "your search had no web results"), $source);
	
	// check AltaVista
	$source = 'http://www.altavista.com/web/results?itag=wrx&q=linkdomain%3A'.$target.'&kgs=1&kls=0';
	$data['AltaVista'] = array(fetch($source, 'altavista found', 15, 'results', "we found 0 results"), $source);
}
?>

This is the original table that came with it, which works with the above:

Code:
<form action='<?php echo $_SERVER[PHP_SELF]; ?>' method='post'>
	<table width='350' border='0' cellpadding='3' cellspacing='0'>
		<tr>
			<td colspan='2'>
			
			</td>
		</tr>
		<tr>
			<td>
				<label for='target'>Website URL</label>
			</td>
			<td>
				<input type='text' name='target' id='target' value='<?php echo $_POST[target]; ?>' style='width:200px;'/>
			</td>
		</tr>
		<tr>
			<td></td>
			<td>
				<input type='submit' value='Submit'/>
			</td>
		</tr>
	</table>
	<?php
	// display data summary
	if($data) {
		echo "<br/><table width='350' border='0' cellpadding='3' cellspacing='0'>";
		echo "<tr><td align='center' colspan='2'><b>Link Popularity Report</b></td></tr>";
		echo "<tr><td><b>Search Engine</b></td><td align='right'><b>Indexed Links</b></td></tr>";
		foreach($data as $engine => $result) {
			echo "<tr><td><a href='$result[1]' target='_blank'>$engine</a></td><td align='right'>";
			if($result[0])
				echo $result[0];
			else
				echo 'Not Available';
			echo '</td></tr>';
			$total += ereg_replace("[[:punct:]]", '', $result[0]);
		}
		echo "<tr><td><b>Total</b></td><td align='right'><b>$total</b></td></tr>";
		echo '</table>';
	}
	?>
	<input type='hidden' name='submit' value='true'/>
	</form>

And this is the script in action: http://www.york-interweb.com/link_report.php

It's pretty much what I had in mind, but I might play with results display to include popular websites to compare with. :)
 

phlash

Fledgling Freddie
Joined
Dec 24, 2003
Messages
195
OK Maljonic :cool: As you can see, that's a page scraper that hits the other engines, then parses the returned HTML for count values in the text.. it'll work until they change their page layout or text (hopefully not too often) in which case you'll need to try the broken search yourself and alter the text patterns used to scrape the values off the page.

Best of luck!
 

Users who are viewing this thread

Top Bottom