ctaylo21 0 Junior Poster in Training

Hello all,
I have a script that displays the graphs of the rain gauges that the user selects on my site. They check all the gauges they want to see, and then when they click submit, my script then searches another site for the graph for each gauge using that gauges id number. These graphs are all displayed in a new window. Everything works fine, but my problem is that occasionally I get the "broken image" image instead of my image. But usually, if you try it again, that image is displayed. I'm not very experienced with PHP, but can this be helped at all? Is the script perhaps timing out and giving up on the image? (although I doubt this, the images all appear within 15 seconds, even if you select 15 gauges.)

///the id variable is one large string that has many different id numbers separated by "^" which are then separated out again.
<?php 
$myVar = $_GET["id"];
if($myVar=="")
  echo "Please make a selection";
else
{
	$delimiter = '^';
	 $myVar = explode($delimiter, $myVar);
	 $total=0;
	 while(array_key_exists($total, $myVar))
	 {
	   $my_id = $myVar[$total];
	           ?>
		          <img src = "<?php echo "g2.php?id=".$my_id; ?>" />
		       <?php 
		       $total++;
			 
	 } 
}
         
	       

?>

//And g2.php

<?php
Header ('Content-type: image/gif');
$id = $_GET['id'];

$url_data = "(omitted)" . $id ."";
$url_data = file_get_contents($url_data);

$graph_regex = "/<img\ssrc=\"[^>](.*)>/siU";

preg_match_all($graph_regex,$url_data,$idlinks);
$index=-1;

for($i=0; $i<count($idlinks[1]); $i++){
	if(strpos($idlinks[1][$i], "omitted") > -1){
		
		if(strpos($idlinks[1][$i], ".00065.") > -1)
	    {
			$index=$i;
			break;
		}
	}
}
if($index == -1)
{
    $final_url="../stylesheets/images/blank.gif";
	$img = imagecreatefrompng($final_url);
}
else
{
	$final_url = "(omitted)".$idlinks[1][$index];
	$end = strpos($final_url, "border");
	$final_url = substr($final_url, 0, $end-2);

	$img = imagecreatefrompng($final_url);
	
}

imagegif($img);
imagedestroy($img);
?>

Any help would be appreciated. Sorry for the the lame attempts at "security" by omitting urls.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.