Kira Yamato
Kira Yamato

Reputation: 1

Why I can't get website content using CURL

I'm really confused. My problem is I can't get website content using curl I've tried to display the result but it always the same result, it always return an empty string..

Here is my function :

function get_html_content($url, $timeout=10) {
    // fake user agent
    $userAgent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
    //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    $string = curl_exec($ch);
    curl_close($ch);

    return $string;
}

Is there anything wrong with my code above, because whenever I try the above code, it always return an empty string.

Upvotes: 0

Views: 2034

Answers (1)

Raj
Raj

Reputation: 22926

As mentioned in the comments, adding

CURLOPT_PROXY

with appropriate proxy settings solved the problem.

Upvotes: 1

Related Questions