tags:

views:

99

answers:

2

Hello,

I want to check if an URL exists using PHP. for eg. If someone enters www.adflkjweoifj123912873.com, I want to check if this domain has a website, or its live on the web.

Thanks Jean

+5  A: 

Curl: curl_getinfo($curl,CURLINFO_HTTP_CODE);

See for implementation details http://www.php.net/curl

If you only want to verify it is registered you could do a gethostbyaddr(), which doesn't mean the IP is reachable or the site exists.

Wrikken
cURL surely offers a solution but is also rather slow and may have an impact on the performance of an app :(
Ain
I don't really see an alternative unless you want to do somesort of AJAX on the frontend as the user is filling in the form (assuming this is a form of course)
paullb
A js check is not the way to go when checking user input. If they are willingly giving a false domainname, bypassing a js check is perhaps less trivial but easily done. Curl may be somewhat slower, but more reliable, and one could even opt for a head request instead of a full repsonse.
Wrikken
+2  A: 

checkdnsrr will be usefull . Searches DNS for host/ip strings.

Arsheep