2010-02-09 91 views
1

实施例:http://www.whois.net/whois/hotmail.comPHP中使用CURL抓住WHOIS记录

当浏览器中打开,示出了输出。

使用卷曲调用时,它什么都不显示。

怎么了?我想返回整个页面结果,然后使用正则表达式在截止日期:29-Mar-2015 00:00:00行检索数据。

$postfields= null; 
$postfields["noneed"] = ""; 
$queryurl= "http://www.whois.net/whois/hotmail.com"; 

$results= getUrlContent($postfields, $queryurl); 
echo $results; 


function getUrlContent($postfields,$api_url) 
{ 
    if(!extension_loaded('curl')){die('You need to load/activate the cURL extension (http://www.php.net/cURL).'); } 

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $api_url); // set the url to fetch 
    curl_setopt($ch, CURLOPT_HEADER, 0); // set headers (0 = no headers in result) 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // type of transfer (1 = to string) 
    curl_setopt($ch, CURLOPT_TIMEOUT, 10); // time to wait in seconds 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); 
    $content = curl_exec($ch); // make the call 
    curl_close($ch); 
    return $content; 
} 
+0

什么是在这个问题上与正则表达式? – 2010-02-09 04:06:43

+0

删除了正则表达式引用。他们可能希望在从CURL获得结果后使用正则表达式,这可以通过我最后的评论来避免。 – Anthony 2010-02-09 04:12:53

+0

请确保您阅读 - http://www.whois.net/terms-and-conditions,尤其是以下部分:您无权访问或查询WHOIS.NET系统,通过 使用电子程序,量和自动 除非合理必要注册域名或修改现有注册。 – 2011-08-09 20:12:37

回答

3

Whois.net检查user agent。因此,这些添加到你的函数调用curl_exec

$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"; 
curl_setopt($ch, CURLOPT_USERAGENT, $useragent); 
0

之前,你看到的错误是不相关的whois.com,就说明你没有启用卷曲模块为PHP。先尝试启用PHP cURL模块。

关注这个线程,如果你不知道如何启用PHP卷曲模块:How to enable cURL in PHP/XAMPP

希里什