views:

51

answers:

2

I'd like to run checks to see if a given URL is registered or not. As a simple proxy for testing if it's registered, I was going to check HTML response codes. 200, 300 probably == registered, 4xx probably == not registered.

I understand that there might be holes in this logic. My question is if cURL has a way to return the HTML response code neatly? I currently can print out the entire header, and am wondering if I need to parse out the bit I want on my own, or if it can return the whole header as an array.

A direct answer or a great alternative would both be welcome.

+3  A: 

The biggest hole in this logic is that just because a domain is registered doesn't mean it has a web server running at it.

The best way to tell if a domain is registered is to do a whois check. In PHP there's the PEAR::Net_Whois library for that.

The second biggest hole in your logic is that if a domain is responding to requests--whether 200, 300, or 404, it's definitely registered. But, if you do just want to check the response code, the correct way is to do an HTTP HEAD request, which tells the server you don't want a complete response, just the headers. You can do with PHP's cURL library by setting CURLOPT_CUSTOMREQUEST to 'HEAD':

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
Jordan
I second that, though you should add not all servers respond to HEAD request.
Gordon
A: 

take a look at checkdnsrr()

Alix Axel