Checking if URL Exists

James

Well-known member

I'm trying to create a custom identity service - which I managed - however I'd like to run a check to see if the ID provided is actually a real ID.

I can do this by resolving a URL and checking for a status code (404 - page not found) but I'm not sure how to go about it. I know I'll have to put the check in the verifyAccountName() function, but is there a function I can use apart from cURL?
 
You could do something like this:

Code:
$url = "http://www.example.com/index.php";
$header_response = get_headers($url, 1);
if ( strpos( $header_response[0], "404" ) !== false )
{
  // FILE DOES NOT EXIST
} 
else 
{
  // FILE EXISTS!!
}
 
I'll try that one ASAP bambua. I've found cURL to be pretty intensive and slow, I need a quick method - so yours seems a good option.
 
Top Bottom