I need to create a function that returns if a URL is reachable or valid.
I am currently using something like the following to determine a valid url:
You can use curl as follows:
$ch = curl_init($url); curl_setopt($ch, CURLOPT_NOBODY, true); // set to HEAD request curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // don't output the response curl_exec($ch); $valid = curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200; curl_close($ch);