1

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

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

3 Comments

cURL surely offers a solution but is also rather slow and may have an impact on the performance of an app :(
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)
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.
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.