• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Checking if URL Exists

James

Well-known member
#1

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?
 

bambua

Well-known member
#2
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!!
}
 

James

Well-known member
#3
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.