获取当前页面的状态代码时出错 - PHP

时间:2012-11-12 05:56:00

标签: php sockets http-status-code-404

获取这个是我管理的php片段

$server="localhost";
function sockAccess($page)
{
   $errno="";
   $errstr="";
   $fp=0;
   global $server;
   $fp=fsockopen($server,80,$errno,$errstr,30);

   if($fp===0)
   {
      die("Error $errstr ($errno)");
   }
   $out="GET /$page HTTP/1.1\r\n";
   $out.="Host: $server\r\n";
   $out.="Connection: Close\r\n\r\n";

   fwrite($fp,$out);
   $content=fgets($fp);
   $code=trim(substr($content,9,4));
   fclose($fp);
   return intval($code);
}
//echo '".'.$_SERVER["REQUEST_URI"].'"';
//echo '"php self='. $_SERVER['PHP_SELF'].'"';
if(($_SERVER['PHP_SELF']) == ($_SERVER['REQUEST_URI'])}
{
echo "code=", " ", sockAccess('".'.$_SERVER["REQUEST_URI"].'"'), "\n";
}
else
{
echo "code=", " ", sockAccess('".'.$_SERVER["REQUEST_URI"].'"'), "\n";
}
echo "code=", " ", sockAccess("./test.php"), "\n";

echo "code=", " ", sockAccess("brokenlink.php"), "\n";

问题是它仍然显示code=404为echo "code=", " ", sockAccess('".'.$_SERVER["REQUEST_URI"].'"'), "\n"; 所以我认为解决方案可能是它没有读取已经运行的文件。所以我通过使用if else thing修改了bove代码。但是现在提交文件dosent run.Is this wrong.Thankx提前。

0 个答案:

没有答案