CURL alternative to fopen

SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
Watch

Momo

VIP Member
Impact
72
I'm installing a script which uses the fopen function, but my host Dreamhost has disabled this feature for security reasons. The suggested alternative was to use CURL, but I'm clueless as to what should I replace the code with.

Here is the part of the code which uses the said function:

Code:
$file = fopen($filename, "r");
        if (!$file) 
        {
            echo "<p>Unable to open remote file $filename.\n";
        }
        else
        {
            while (!feof($file))
            {
                $var = fgets($file, 1024);
                if(eregi("<font color=#008000>(.*)</font><nobr>",$var,$out))
                {
                    $out[1] = strtolower(strip_tags($out[1]));

$s1=str_replace("http://","",$out[1]);  
$ur1=str_replace("www.","",$s1);
$s=strpos($ur1," ");
if ($s > 3)$ur1=substr($ur1,0,$s);
$s=strpos($ur1,"/");
if ($s > 3)$ur1=substr($ur1,0,$s);
$ur1=str_replace("/","",$ur1);

                    $position++;
           
                   if($ur==$ur1)
                    {
                        $found = $position;          
                        break;
                    } 
                }
            }
        }
        fclose($file);    
    }

Could anybody guide me as to how to replace the fopen, fgets, etc functions with the CURL alternatives? Thanks a lot!
 
1
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Something like:
PHP:
$url = 'http://www.someurl.com/';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$var = curl_exec($ch);

if(eregi("<font color=#008000>(.*)</font><nobr>", $var, $out))
{
  $out[1] = strtolower(strip_tags($out[1]));
  $s1 = str_replace("http://", "", $out[1]);
  $ur1 = str_replace("www.", "", $s1);
  $s = strpos($ur1, " ");

  if($s > 3)
  {
    $ur1=substr($ur1, 0, $s);
  }
  $s = strpos($ur1, "/");

  if($s > 3)
  {
    $ur1 = substr($ur1, 0, $s);
  }
  $ur1 = str_replace("/", "", $ur1);
  $position++;

  if($ur == $ur1)
  {
    $found = $position;
    break;
  }
}
//Once done with everything...
curl_close($ch);
 
1
•••
Thank you SecondVersion, the code your posted worked well for me! :D Thanks again!
 
0
•••
No problem :)
 
0
•••
CatchedCatched

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

New in Parking: updated way to act on many domains or inquiries at once
Your domain list and inquiry list now have a bar above and below the list. Check the items you want, then choose an action in the bar...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back