NameSilo

CURL alternative to fopen - Revisited

Spaceship Spaceship
Watch

Hossam

New Member
Impact
0
Hello!

There is already a thread that was created that touched on this issue, but it was locked.

My host provider is no longer allowing fopen and fgets command calls due to security issues and CURL was suggested as an alternative method to achieve the same results.

Here is a snippet of the code which is giving errors in my php script:

Code:
if($address!='')
{
	$fp  = fopen($address,"r");
	$i=0;
	while($i<1000){
		$html_data.=fgets($fp);
		$i++;
}

I know this is probably a very simple fix, but my knowledge of CURL is limited at best, any help would be appreciated! Thank you.
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
0
•••
Darn, i tried this but I don't get the result as the prior script

PHP:
if($address!='')
{    
                $fp = curl_init();
                curl_setopt($fp, CURLOPT_URL, $address);
                curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($fp, CURLOPT_FORBID_REUSE, true);
                curl_setopt($fp, CURLOPT_FRESH_CONNECT, true);
                curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, 3);
                curl_setopt($fp, CURLOPT_TIMEOUT, 10);
                curl_setopt($fp, CURLOPT_HTTPHEADER, array('Connection: close'));

                $html_data = curl_exec($fp);
}

The page renders blank! Any suggestions?
 
Last edited:
0
•••
This should work :)
PHP:
$curlurl = 'http://something.com';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $curlurl);
curl_setopt($ch, CURLOPT_REFERER, $curlurl);
curl_setopt($ch, CURLOPT_USERAGENT, getenv('HTTP_USER_AGENT'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$curlresult = curl_exec($ch);
curl_close($ch);

echo($curlresult);
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer
Appraise.net

We're social

Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back