Kamis, 21 Oktober 2010

PHP cURL function to get Data from Web

Source : http://davidwalsh.name/download-urls-content-php-curl


 

    function get_data($url)

    {     

        $userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)";

        

        $ch = curl_init();

        $timeout = 5;

        

        curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);

        curl_setopt($ch, CURLOPT_URL,$url);

        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,$timeout);

        curl_setopt($ch, CURLOPT_FAILONERROR, true);

        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

        curl_setopt($ch, CURLOPT_AUTOREFERER, true);

        curl_setopt($ch, CURLOPT_TIMEOUT, 10);

        

        $data = curl_exec($ch);

        curl_close($ch);

        return $data;

    }

0 komentar:

Posting Komentar

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More