Question: I am getting a image source from a URL dynamically, but sometimes the URL returns empty or the image does not exist so i created a `PHP` function to check if the image source do exist or not so i can display a default image to my users when the image is not accessible.

My concern, is my function enough to catch the data?

My current php function which works when its sure that a image do exist.

```
function get_image_by_id($ID) {

  $url = 'http://proweb/process/img/'.$ID.'.jpg'; 

  if(empty($url)){

   return 'default.jpg';

   }else{

    return $url;

  }

}

```

My index.php 

```
<img src="<?php echo get_image_by_id($ID);?>" />

```

Answer: 
you can use like this

```
<?PHP 
function get_image_by_id($ID) {

  $url = 'http://proweb/process/img/'.$ID.'.jpg';
// Checks to see if the reomte server is running 
       if(file_get_contents(url) !== NULL) 
        { 
            return  $url; 
        } 
       else
        { 
             return 'default.jpg';
        } 
}
?>

```
```
function get_image_by_id($ID) {
 if(empty($url)){
$url = 'http://proweb/process/img/default.jpg; 
}else{
$url = 'http://proweb/process/'.$ID.'.jpg'; 
 }
return $url
}

```