1

Example: http://www.whois.net/whois/hotmail.com

When open in browser, output is shown.

When using curl call, it show nothing.

What's wrong? I want to return whole page result, then use regular expression to retrieve data at Expiration Date: 29-Mar-2015 00:00:00 line.

$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;
 } 
codaddict
  • 445,704
  • 82
  • 492
  • 529
i need help
  • 2,386
  • 10
  • 54
  • 72
  • What is related to regular expressions in this question? – Emre Yazici Feb 09 '10 at 04:06
  • Removed the regex references. They probably want to use regex after getting results from CURL, which can be avoided with my last comment. – Anthony Feb 09 '10 at 04:12
  • Make sure you read - http://www.whois.net/terms-and-conditions, specially this part: You are not authorized to access or query the WHOIS.NET system through the use of electronic processes that are high-volume and automated except as reasonably necessary to register domain names or modify existing registrations. – Pedro Lobito Aug 09 '11 at 20:12

2 Answers2

3

Whois.net checks user agent. So add these to your function before you call 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);
codaddict
  • 445,704
  • 82
  • 492
  • 529
1

The error you see is not related to whois.com, it shows you have not enabled cURL module for your PHP. Try enabling the PHP cURL module first.

Follow this thread if you are not sure how to enable PHP cURL module: How to enable cURL in PHP / XAMPP

Shirish

Community
  • 1
  • 1