0

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.

Adi
  • 1
  • 4

2 Answers2

0

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.

Andrew Larsen
  • 1,257
  • 10
  • 21
  • Question's that show no effort shouldn't be answered, IMHO and shared by many. – Funk Forty Niner Dec 30 '16 at 19:55
  • Thank you for your reply. I know that but it will not work for me because several user will use my extensions. so I have to fix it in code stage. if you have better solution in that stage then please let me know. – Adi Dec 31 '16 at 04:26
0

$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.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109