I want to call a file by an url. If the url is not found then I want to show an error message instead of showing "The requested url is not found". How I will do this? Please help me.
Create a .htaccess file in your web directory, and write the following:
ErrorDocument 404 /notfound.html
Make sure to replace notfound.html with your custom 404 html file.
$headers=get_headers($url);
Then check if $result[0] contains 200 OK (which means the file is there)
A function to check if a URL works could be this:
function UR_exists($url)
{
$headers=get_headers($url);
return stripos($headers[0],"200 OK")?true:false;
}
/* You can test a URL like this (sample) */
if(UR_exists("https://www.example.com/"))
echo "This page exists";
else
echo "This page does not exist";
Hope this will help you out.