Checking whether a URL exists in PHP
There is no built in function to check if a particular URL exists, but you can easily write one. The following is a simple method, or you can try this one which takes more code, but allows more control.
Copy and paste the following code into a new file and try it out!
<?php function doesUrlExist($url) { if (!empty($url) && @fopen($url, "r")) { // The URL is not empty and we can read it, so return true return true; } // The URL was either empty, or not found, so return false. return false; } // Test a bad URL $url = "http://www.somedomain.com/index.html"; echo (doesUrlExist($url) ? "The URL at $url exists!" : "The URL at $url could not be found!"); echo ("<br />"); // Test a good URL $url = "http://www.aratide.com"; echo (doesUrlExist($url) ? "The URL at $url exists!" : "The URL at $url could not be found!"); ?>