我有这个链接
http://www.bata.com.sg,这个网站确实存在
在我的curl代码中工作,检查页面是否存在。
它在我的localhost代码中工作,但它在我的实时网站中一直失败。
我已经使用其他域名http://www.yahoo.com.sg进行了测试,它一直在我的本地主机和我的实时网站上运行。
我逐字复制了这段代码http://w-shadow.com/blog/2007/08/02/how-to-check-if-page-exists-with-curl/。
我不明白为什么它失败了这个特殊的网址。
我的网站托管了site5。
我注意到我一直在为这一行弄错(布尔)
curl_exec($ CH);
我为curl_error得到这个无法解析主机'www.bata.com.sg'
请告知。
答案 0 :(得分:4)
您需要与site5的客户支持人员联系,以找出他们的服务器无法解析的原因www.bata.com.sg
在您收到答案之前,请尝试以下代码。
关键点
从本质上讲,它的工作方式与Curl可以解析地址的方式相同。
<?php
// this is the IP address that www.bata.com.sg resolves to
$server = '194.228.50.32';
$host = 'www.bata.com.sg';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $server);
/* set the user agent - might help, doesn't hurt */
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
/* try to follow redirects */
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
/* timeout after the specified number of seconds. assuming that this script runs
on a server, 20 seconds should be plenty of time to verify a valid URL. */
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$headers = array();
$headers[] = "Host: $host";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
/* don't download the page, just the header (much faster in this case) */
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
答案 1 :(得分:0)
我已经找到了原因。
使用这个网站我被告知bata.com.sg的名称服务器存在问题
http://www.intodns.com/bata.com.sg
无论如何,上面的答案也很有用。我从他们身上学到了一些东西。
答案 2 :(得分:-1)
这可能是防火墙问题。有时托管公司可能会限制网络服务器可以咨询的内容。
你也可以确保php_info()中存在curl。我想你没有提到任何错误。
你也试试
file_get_contents('http://www.yahoo.com.sg');