Home > General > How to Check Whether a URL Exists or Not Without Visitting The Page

How to Check Whether a URL Exists or Not Without Visitting The Page

This simple script is very useful for you if you want to check whether a URL exists or not without having to visit the page. This script using PHP, and I have tested it. It worked like a charm. Of course, you need to modify further the way you want, for example, this function will be called when a button is clicked, and so on. But we are not here to discuss these details. This example as simple as possible in the hope that you can develop further according to individual needs.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php  
 
   function checkURL($url) {  
     $check = @fopen($url, "r"); 
     if($check)  
       $status = true;  
     else  
       $status = false;        
     return $status;  
   }  
 
   $url = "http://www.openscriptsolution.com";  // <-- change with other URL
   if(checkURL($url)) {  
     echo "<a href=$url>$url</a> <b>exists</b>.";  
   }  
   else {  
     echo "<a href=$url>$url</a> does <b>not</b> exist.";  
   }  
 
?>
  • Share/Bookmark
88 views Print This Post Print This Post

Categories: General Tags: , , , ,
  1. No comments yet.
  1. No trackbacks yet.