I want to check whether a HTML page exists on another site. More exactly, my users need to upload a .html page onto their own site and after that they need to press “verify now” on my site. My site then needs to confirm that the html page exists on their site.
I found this code:
$url = 'http://domain.tld/my_page.html';
$handle = @fopen($url,'r');
if($handle !== false){
echo 'Page Exists';
} else {
echo 'Page Not Found';
}
But if my_page.html don’t exist, this code returns just “Page Exists”.
Assuming that you have the
curlextension installed in your PHP, I think this by far your best option:Easy way to test a URL for 404 in PHP?