$url, CURLOPT_RETURNTRANSFER => 1, CURLOPT_USERAGENT => $browser ); curl_setopt_array($ch, $curl_options); return curl_exec($ch); } $page = downloadUrl("http://phdcomics.com/comics.php"); $image = preg_match('#http://phdcomics.com/comics/archive/phd[0-9]{6}s.gif#', $page, $matches); if(!empty($image)) { header('Content-type:image/gif'); echo downloadUrl($matches[0]); } else { echo "Sorry, there has been an error."; } ?>