按道理说,依旧我这样写法,就算打不开指定的文件,也不会出现php报错信息啊.
这叫我怎么用fsockopen()啊
这叫我怎么用fsockopen()啊
解决方案 »
- 关于require (strtolower($object) . '.class.php')的问题
- 非常变态的url重写
- php同页面传值怎么写?
- preg_match 匹配mac地址
- 火车票的骗局
- 想问下 搜索引擎 是怎么实现的?
- 请问每个用户都有他自己的空间,这种记录叫什么名字,如何配置?
- 数据库连接失败:mysql_error:Access denied for user 'root'@'localhost'
- 可不可以<?inclue("a.php?para=abc");?> ?
- 打印时如何去掉页面底部的路径和顶端的页码编号
- 高分求救!过来看看!关于刷新的问题
- 如何获取当前页面中的表单数据呀?
$fp = fsockopen($url,80, &$errno, &$errstr, 10);
你的用法是fopen的。
{
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头进去
第二个错误信息是说连接失败(不到目标地址,当然连接失败)目标网站没有工作、dns服务器故障、端口不对都可能造成
请先用浏览器确认目标正确注意:如果你需要使用代理服务器上网的话,请停止这个徒劳的测试
完全代码在这,高手帮我看看
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));
}
}
}
我现在是在本地局域网中测试的,服务器通过网关可以上网,等网站做好后就会直接放在web上,在局域网用此函数为出错?我运行此段代码时好时坏,被请救的地址是没有问题的.