Hey everyone, I know that many SEO'ers and webmasters in general are often checking the PageRank of various websites. So I thought you might find this helpful, the PHP code for your own bulk PR checker. 1. Start by creating a private folder on one of your domains. In order to make the folder private place the following two files in the folder: .htaccess .htpasswd Here is what .htaccess should contain: AuthType Basic AuthName "restricted area" AuthUserFile /home/path/to/your/folder/.htpasswd require valid-user Code (markup): Obviously you will need to enter the correct path on your server. If you're not sure what the path is create a temporary file containing this code and place it in the folder: <?php echo $_SERVER["SCRIPT_FILENAME"]; ?> PHP: Access it and it will display the full path Here is what .htpasswd should contain: johndoe:encrypted_password Code (markup): Replace johndoe with the username of your choice. To generate the encrypted password you can either use your own script or simply google "htpasswd generator", access the first link (I used http://www.htaccesstools.com/htpasswd-generator/), enter your username and password and the tool will generate the encrypted password for you to paste in the .htpasswd file. !Tip If you're using Windows you might not be able to name the files .htaccess and .htpasswd. Simply name them hta.txt and htp.txt and once you've uploaded them on the server rename them to .htaccess and .htpasswd 2. Create a index.php file containing the following code: <html> <head> <title>Bulk Check PageRank</title> </head> <body> <?php if(!$_REQUEST["pages"]) { ?> <form action="/pr.php" method="POST"> Check PageRank: <input type="submit" id="check" value="Check"/> <br/><textarea cols="40" rows="10" name="pages" id="pages"></textarea> </form> <?php } else { ?> PageRanks:<br/> <?php $pages = explode("\r\n",$_REQUEST["pages"]); foreach($pages as $page) { $pr = getpr($page); echo "<b>$page</b> - <span style=\"color:#0A0;font-weight:bold;\">$pr</span><br/>"; } } ?> </body> </html> <?php function getpr($page) { $url = addhttp($page); $escaped = urlencode($url); $pr = final_getpr($url,$escaped); return $pr; } function final_getpr($url,$escaped) { $query="http://toolbarqueries.google.com/tbr?client=navclient-auto&ch=".CheckHash(HashURL($url)). "&features=Rank&q=info:".$escaped."&num=100&filter=0"; $data=crawl($query); $pos = strpos($data, "Rank_"); if($pos === false){} else{ $pagerank = substr($data, $pos + 9); return $pagerank; } } function StrToNum($Str, $Check, $Magic) { $Int32Unit = 4294967296; // 2^32 $length = strlen($Str); for ($i = 0; $i < $length; $i++) { $Check *= $Magic; if ($Check >= $Int32Unit) { $Check = ($Check - $Int32Unit * (int) ($Check / $Int32Unit)); $Check = ($Check < -2147483648) ? ($Check + $Int32Unit) : $Check; } $Check += ord($Str{$i}); } return $Check; } function HashURL($String) { $Check1 = StrToNum($String, 0x1505, 0x21); $Check2 = StrToNum($String, 0, 0x1003F); $Check1 >>= 2; $Check1 = (($Check1 >> 4) & 0x3FFFFC0 ) | ($Check1 & 0x3F); $Check1 = (($Check1 >> 4) & 0x3FFC00 ) | ($Check1 & 0x3FF); $Check1 = (($Check1 >> 4) & 0x3C000 ) | ($Check1 & 0x3FFF); $T1 = (((($Check1 & 0x3C0) << 4) | ($Check1 & 0x3C)) <<2 ) | ($Check2 & 0xF0F ); $T2 = (((($Check1 & 0xFFFFC000) << 4) | ($Check1 & 0x3C00)) << 0xA) | ($Check2 & 0xF0F0000 ); return ($T1 | $T2); } function CheckHash($Hashnum) { $CheckByte = 0; $Flag = 0; $HashStr = sprintf('%u', $Hashnum) ; $length = strlen($HashStr); for ($i = $length - 1; $i >= 0; $i --) { $Re = $HashStr{$i}; if (1 === ($Flag % 2)) { $Re += $Re; $Re = (int)($Re / 10) + ($Re % 10); } $CheckByte += $Re; $Flag ++; } $CheckByte %= 10; if (0 !== $CheckByte) { $CheckByte = 10 - $CheckByte; if (1 === ($Flag % 2) ) { if (1 === ($CheckByte % 2)) { $CheckByte += 9; } $CheckByte >>= 1; } } return '7'.$CheckByte.$HashStr; } function crawl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_REFERER, "http://google".rand().".com"); $output = curl_exec($ch); curl_close($ch); return $output; } function addhttp($url) { if (!preg_match("~^(?:f|ht)tps?://~i", $url)) { $url = "http://" . $url; } return $url; } ?> PHP: If you're going to do heavy work and want to avoid getting a temporary IP ban from Google Toolbar, you can use proxies. If you have a list of proxies you'd like to use simply add the following lines to the crawl function: $proxies = array('127.0.0.1:8888','127.0.0.2:8888','127.0.0.3:8888'); //replace the array with your actual proxies $proxy = $proxies[rand(0,count($proxies)-1)]; $proxyauth = 'user:password'; //replace with your proxy user:password combination curl_setopt($ch, CURLOPT_PROXY, $proxy); curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth); PHP: I hope this will help some of you Just reply to the thread if you need further help or if something doesn't work well for you! Best Regards, Traian
in your code the form references a 'pr.php' you havent included the code for the pr.php file (I assume that the index.php file and the pr.php file are meant to be the same file?) eg : to fix it - change (remove) the action attribute on the form