Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

CURL alternative to fopen

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
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
•••
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

More data. Your data. See what is new
Major update
We have made a number of features available to provide sellers more data for their domains and inquiries, and greater access to the data...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back