Virtuali Posted August 30, 2009 Share Posted August 30, 2009 Hello. I am currently trying to make a small script that will calculate the seo data of any website and then store this in a database for a sort of ranking directory for a small niche. However I am having a problem with a code i found on the net to get pagerank. The code work well when i test it on php4.3.10 on my localhost and display the correct pr. But when i upload it to my server using php5 it does no more echo the result. Below is the code i am using and which is working on php4 bt not on php 5. <?php function ZeroFill($a,$b){ $z=hexdec(80000000); if($z&$a){ $a=($a>>1); $a&=(~$z); $a|=0x40000000; $a=($a>>($b-1)); }else{ $a=($a>>$b); } return $a; } define('GOOGLE_MAGIC',0xE6359A60); function Mix($a,$b,$c){ $a-=$b;$a-=$c;$a^=(ZeroFill($c,13)); $b-=$c;$b-=$a;$b^=($a<<; $c-=$a;$c-=$b;$c^=(ZeroFill($b,13)); $a-=$b;$a-=$c;$a^=(ZeroFill($c,12)); $b-=$c;$b-=$a;$b^=($a<<16); $c-=$a;$c-=$b;$c^=(ZeroFill($b,5)); $a-=$b;$a-=$c;$a^=(ZeroFill($c,3)); $b-=$c;$b-=$a;$b^=($a<<10); $c-=$a;$c-=$b;$c^=(ZeroFill($b,15)); return array($a,$b,$c); } function GoogleCH($url,$length=null,$init=GOOGLE_MAGIC){ if(is_null($length)){ $length=sizeof($url); } $a=$b=0x9E3779B9; $c=$init; $k=0; $len=$length; while($len>=12){ $a+=($url[$k+0]+($url[$k+1]<<+($url[$k+2]<<16)+($url[$k+3]<<24)); $b+=($url[$k+4]+($url[$k+5]<<+($url[$k+6]<<16)+($url[$k+7]<<24)); $c+=($url[$k+8]+($url[$k+9]<<+($url[$k+10]<<16)+($url[$k+11]<<24)); $mix=Mix($a,$b,$c); $a=$mix[0];$b=$mix[1];$c=$mix[2]; $k+=12; $len-=12; } $c+=$length; switch($len){ case 11:$c+=($url[$k+10]<<24); case 10:$c+=($url[$k+9]<<16); case 9:$c+=($url[$k+8]<<; case 8:$b+=($url[$k+7]<<24); case 7:$b+=($url[$k+6]<<16); case 6:$b+=($url[$k+5]<<; case 5:$b+=($url[$k+4]); case 4:$a+=($url[$k+3]<<24); case 3:$a+=($url[$k+2]<<16); case 2:$a+=($url[$k+1]<<; case 1:$a+=($url[$k+0]); } $mix=Mix($a,$b,$c); return $mix[2]; } function StringOrder($string){ for($i=0;$i<strlen($string);$i++){$result[$i]=ord($string{$i});} return $result; } $target=trim($_POST['txturlsub']); if($target!=""){ $server="www.google.com"; /* Alternative Server $server="toolbarqueries.google.com"; $server="64.233.161.99"; $server="64.233.161.104"; $server="66.102.7.99"; $server="66.102.7.104"; $server="216.239.59.99"; $server="216.239.59.104"; $server="216.239.37.104"; $server="216.239.39.99"; $server="216.239.39.104"; $server="66.102.11.99"; $server="66.102.11.104"; $server="216.239.57.99"; $server="216.239.57.104"; $server="66.102.9.99"; $server="66.102.9.104"; $server="216.239.53.99"; $server="216.239.53.104"; */ $url="info:"."$target"; $ch=trim(str_replace("-","",sprintf("6%u\n",GoogleCH(StringOrder($url))))); $res="http://$server/search?client=navclient-auto&ch=$ch&features=Rank&q=$url"; $data=@fopen("$res",r); if($data){ while($line = fgets($data,1024)) { if(substr($line,0,7)=="Rank_1:"){$rankline = $line;} } fclose($data); $pagerank = trim(substr($rankline,9,2)); if($pagerank==""){$pagerank="0";} } } ?> <b>The pagerank is: <? echo $pagerank; ?></b> The line: $target=trim($_POST['txturlsub']); is the code to fetch the url for which i want the pagerank...I am entering url on another page and then sending here to display. Anyone please can help how to make this work on php5? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/172454-solved-code-working-on-php4-but-not-on-php5-s/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 30, 2009 Share Posted August 30, 2009 Add the following two lines of code immediately after the first opening <?php tag to display all php detected errors - ini_set("display_errors", "1"); error_reporting(E_ALL); Change the following line of code - $data=@fopen("$res",r); // sloppy programming and has nothing to do with php version to this - $data=fopen($res,'r'); And change the following line of code (sloppy programming that has nothing to do with php version) - <b>The pagerank is: <? echo $pagerank; ?></b> to this - <b>The pagerank is: <?php echo $pagerank; ?></b> Quote Link to comment https://forums.phpfreaks.com/topic/172454-solved-code-working-on-php4-but-not-on-php5-s/#findComment-909215 Share on other sites More sharing options...
Virtuali Posted August 31, 2009 Author Share Posted August 31, 2009 Hey man thanks a lot. It works now. Quote Link to comment https://forums.phpfreaks.com/topic/172454-solved-code-working-on-php4-but-not-on-php5-s/#findComment-909492 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.