What alternatives to fopen and file_exists can be used to verify the existence of a script on an external server?

When verifying the existence of a script on an external server, alternatives to fopen and file_exists can include using cURL to make a HEAD request to the URL of the script. This method will check if the script exists without downloading its contents. Another option is to use the get_headers function to retrieve the headers of the URL and check for a successful response code (e.g., 200 for OK).

$url = 'http://www.example.com/script.php';

// Using cURL to make a HEAD request
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($httpCode == 200) {
    echo 'Script exists.';
} else {
    echo 'Script does not exist.';
}