按道理说,依旧我这样写法,就算打不开指定的文件,也不会出现php报错信息啊.
这叫我怎么用fsockopen()啊

解决方案 »

  1.   

    $url="blog.donews.com";  //或者 $url="61.135.128.148";
    $fp = fsockopen($url,80, &$errno, &$errstr, 10);
      

  2.   

    打开手册好好看。
    你的用法是fopen的。
      

  3.   

    这里有一段函数,模拟http请求的,不知你是否用得上print_r(HTTPrequest('get', 'www.w3.org', '/'));function HTTPrequest ($method, $host, $usepath, $postdata = "" )
    {
    if (is_array($postdata)) {
    foreach ($postdata as $key=>$val) {
    if(!is_integer($key))
    $data .= "&$key=".urlencode($val);
    }
    $data = substr($data, 1);
    } else {
    $data = $postdata;
    } $fp = fsockopen($host, 80, &$errno, &$errstr, 30); if (!$fp) {
    print "$errstr ($errno)<br>\n";
    return false;
    } else {
    if (strtoupper($method) == "GET") {
    $headers = "GET $usepath HTTP/1.1\r\n";
    } else if (strtoupper($method) == "POST") {
    $headers =  "POST $usepath HTTP/1.1\r\n";
    }

    $headers .= "Host: $host\n";
         $headers .= "Connection: close\r\n";
        
         //$headers .= "Accept-Encoding: gzip\r\n";
        
    if (strtoupper($method) == "POST") {
    $strlength = strlen($data);
    $headers .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $headers .= "Content-Length: ".$strlength."\r\n";
    }

    $headers .= "\r\n";

    $headers .= "$data\r\n";
        
    fputs($fp, $headers);
        
    while (!feof( $fp )) {
    $output[] = fgets($fp, 1024);
    }

    fclose( $fp);

    return $output;
    }
    }可以自己加一些诸如refer,agent一类的http头进去
      

  4.   

    第一个错误信息是说找不到目标地址
    第二个错误信息是说连接失败(不到目标地址,当然连接失败)目标网站没有工作、dns服务器故障、端口不对都可能造成
    请先用浏览器确认目标正确注意:如果你需要使用代理服务器上网的话,请停止这个徒劳的测试
      

  5.   

    我的应该没有错啊
    完全代码在这,高手帮我看看
    function my_rss($url,$num="") {
    global $glo_title;
    global $glo_link;
    global $glo_description;
    global $glo_date;


    $rdf = parse_url($url);
    $fp = fsockopen($rdf['host'], 80, &$errno, &$errstr, 10);


    if (!$fp) {
    $content = "error";
    echo $errno.":".$errstr."<br>";
    return;
    }
    if ($fp) {
    fputs($fp, "GET " . $rdf['path'] . "?" . $rdf['query'] . " HTTP/1.0\r\n");
    fputs($fp, "HOST: " . $rdf['host'] . "\r\n\r\n");
    $string = "";
    while(!feof($fp)) {
    $pagetext = fgets($fp,300);
    $string .= chop($pagetext);
    }
    fputs($fp,"Connection: close\r\n\r\n");
    fclose($fp);
    $items = explode("</item>",$string);
    $content = "<font class=\"content\">";
    if ($num==""){
    $num=count($items)-1;
    }
    for ($i=0;$i<$num;$i++) {
    $link = ereg_replace(".*<link>","",$items[$i]);
    $link = ereg_replace("</link>.*","",$link);
    $title2 = ereg_replace(".*<title>","",$items[$i]);
    $title2 = ereg_replace("</title>.*","",$title2);
    $description = ereg_replace(".*<description>","",$items[$i]);
    $description = ereg_replace("</description>.*","",$description);
    $thedate = ereg_replace(".*<pubDate>","",$items[$i]);
    $thedate = ereg_replace("</pubDate>.*","",$thedate);


    $glo_title[$i]=strip_tags(iconv('utf-8','gb2312' ,$title2));

    $glo_link[$i]=iconv('utf-8','gb2312' ,$link);
    $glo_description[$i]=strip_tags(iconv('utf-8','gb2312' ,$description));

    $glo_date[$i]=strip_tags(iconv('utf-8','gb2312' ,$thedate));

    }
    }

    }
      

  6.   

    xuzuning(唠叨) ,
    我现在是在本地局域网中测试的,服务器通过网关可以上网,等网站做好后就会直接放在web上,在局域网用此函数为出错?我运行此段代码时好时坏,被请救的地址是没有问题的.
      

  7.   

    我还有一个从fsockopen()取出字符,但"<p>"总会转成"&lt;",请问如何才能把它转会来.我开个新贴,希望高手指点一下