php link directory mod : page rank per page
juust | 20/08/2008Lets add a seo stats plug in to phpLinkDirectory, page rank per page, same method as the Socialize bookmark plug-in.
The actual code to retrieve the pagerank is in pr.php, so I only need a tiny bit of code for prank.php :
-
include('pr.php');
-
$URL = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
-
$prank = pagerank($URL);
-
$tpl->assign('prank', $prank);
I zipped the files :
- put pr.php and prank.php in the link directory root
- add require_once ‘prank.php’; to index.php (below “require_once ‘init.php’;”)
- add {$prank} somewhere in footer.tpl
Enjoy.
If you are commercially smart, you want to make sure a rank shows only if the page actually has a rank. In pr.php, change the function curl_getpr() :
-
if(!$data) {
-
curl_close($cr);
-
unset($cr);
-
-
// $pr="not ranking";
-
$pr = "";
-
-
return $pr;
-
} else {
-
$pos = strpos($data, "Rank_");
-
if($pos === false){} else{
-
$pr=substr($data, $pos + 9);
-
$pr=trim($pr);
-
$pr=str_replace("\n",'',$pr);
-
curl_close($cr);
-
unset($cr);
-
-
// return $pr;
-
return "This page has a Google pagerank of ".$pr;
-
-
}
-
}
-
}
Then, only if you have a rank you get an actual remark in the footer.
In case of trouble :
pr.php uses the cUrl library, if cUrl does not work on your server,
www.highrankforum.com/ has a version without cUrl.
If you are on an IIS server and get in trouble, on IIS the $_SERVER['REQUEST_URI'] serverside
variable is empty.
Try using $_SERVER['SCRIPT_NAME'].$_SERVER['PATH_INFO'] in stead of $_SERVER['REQUEST_URI'] in prank.php :
$URL = “http://” . $_SERVER["HTTP_HOST"] . $_SERVER['SCRIPT_NAME'].$_SERVER['PATH_INFO'];









So the higher the page rank the better?
No, pagerank is only one indicator. A link from a high pr page is as useful to the page it links to as the pages subjects overlap, when it comes to a pages place on a result list in Google Search.