PHP: Check if a URL exists with cURL

In my previous post about email validation one user pointed out that this will not actually validate if a website’s domain actually exists. Here is a simple function that will do just that, determine if a website exists using PHP and cURL.

Edit: After searching a bit, I found another similar cURL solution that checks the actual headers. Since cURL can return HTTP code I don’t think all that extra code is necessary? I could be wrong!

  • Jah_paco

    you could use php get_headers function

  • Abc

    where is the main php piece calling the function?

  • Captain. J

    hi bill, thank you so much. it’s work for me 🙂

  • Andrey Solovey

    Good tip, thanks! The only addition – you set a top limit of server response to 300, but what about 301 redirect?