duanpu1064 2012-02-06 18:49
浏览 35

为什么这个PHP代码在远程主机上不能正常工作,但在localhost上运行良好

I use this code to get google page rank. it works perfect on my local host but it returns zero rank when I use it on my host(linux-php5). code:

<html>
<head>
<title>GPR</title>
<body>
<?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<<8);
  $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]<<8)+($url[$k+2]<<16)+($url[$k+3]<<24));
    $b+=($url[$k+4]+($url[$k+5]<<8)+($url[$k+6]<<16)+($url[$k+7]<<24));
    $c+=($url[$k+8]+($url[$k+9]<<8)+($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]<<8);
    case 8:$b+=($url[$k+7]<<24);
    case 7:$b+=($url[$k+6]<<16);
    case 6:$b+=($url[$k+5]<<8);
    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]<<8);
    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;
}
$url="Yahoo.com";
$server="toolbarqueries.google.com";

  $url="info:"."$url";
  $ch=trim(str_replace("-","",sprintf("6%u
",GoogleCH(StringOrder($url)))));
  $res="http://$server/tbr?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);
    if (isset($rankline)==false){$rankline="";};
    $pagerank = trim(substr($rankline,9,2));
    if($pagerank==""){$pagerank="0";}
    echo <<<HEADER


<table border=0>
HEADER;
echo "<td nowrap colspan=2><a href=\"http://".$url."\">".$url."</a></td>
";
echo "</tr>";
echo "<tr>";
echo "<td nowrap>Pagerank:&nbsp;&nbsp;</td>";
echo "<td nowrap><b>".$pagerank."</b>&nbsp;&nbsp;</td>
";
$out = ''; 
echo $out;
echo <<<FOOTER
</table>
</td></tr></table>
</blockquote>
FOOTER;
}

?>
</body>
</html>

Why is that? and how can I fix it?

  • 写回答

2条回答 默认 最新

  • doubi7306 2012-02-06 18:52
    关注

    Does your host allow you to use fopen for external URLs? You may need to use CURL.

    First thing to do is verify that that allow_url_fopen is enabled on that host.

    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效