Adapting PHP script to use cURL?



I’ve tried to adapt the following script to use cURL, but being basically a “cut and paste” coder, I’m not having much luck. Can anyone help out? This script/feature was one of my major sources of incoming links at my last host, so I’d really like to get it working again ASAP. Thanks everyone!

<?php $threat = eregi_replace('.*CONDITION="(.*)" />', '\1', implode('\n', file(""))); header("Content-type: image/png"); if (preg_match("/SEVERE/", $threat)) {$image = imagecreatefrompng("Cthulhu.png");} elseif (preg_match("/HIGH/", $threat)) {$image = imagecreatefrompng("Borg.png");} elseif (preg_match("/ELEVATED/", $threat)) {$image = imagecreatefrompng("Vader.png");} elseif (preg_match("/GUARDED/", $threat)) {$image = imagecreatefrompng("Dalek.png");} elseif (preg_match("/LOW/", $threat)) {$image = imagecreatefrompng("Dobby.png");} imagePNG($image);


That is the only line you should need to worry about. Try replacing it with this:

$ch = curl_init(); $timeout = 5; curl_setopt ($ch, CURLOPT_URL, ''); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $file_contents = curl_exec($ch); curl_close($ch); $remote_url = array(); $remote_url = explode("\n", $file_contents); $threat = eregi_replace('.*CONDITION="(.*)" />', '\1', implode('\n', $remote_url));--------
Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]


Brilliant! Thanks. :slight_smile: I’d tried almost the exact same thing, but didn’t have this line included: $remote_url = explode("\n", $file_contents);

Works perfectly now. Do you want me to credit you in the code for helping? If so, just let me know how. :slight_smile:


Your thanks are more than sufficient (and more than I usually get LOL).

Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]


heh. Well, OK. But if someone specifically requests the cURL version of the script, I might sneak an attribution in there anyhow. :wink: Thanks again!