NamePros.Com (http://www.namepros.com/)
-   Programming (http://www.namepros.com/programming/)
-   -   CURL alternative to fopen - revisited (http://www.namepros.com/programming/463335-curl-alternative-to-fopen-revisited.html)

Hossam 04-29-2008 07:11 AM

CURL alternative to fopen - revisited
 
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.

Daniel 04-29-2008 08:44 AM

www.php.net/curl

Very easy to use! :tu:

Hossam 04-29-2008 10:17 AM

Darn, i tried this but I don't get the result as the prior script

PHP Code:
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?

xrvel 04-30-2008 12:20 AM

This should work :)
PHP Code:
$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);


All times are GMT -7. The time now is 06:33 PM.
Site Sponsors
Advertise your business at NamePros

Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0