Benekiki
Benekiki

Reputation: 101

Alternative to file gets content and curl to get html code from a page

I am using the following code to get the html code of a page and extract the price later on for a price comparator :

<?php
function url_get_contents ($url) {
    if (function_exists('curl_exec')){ 
        $conn = curl_init($url);
        curl_setopt($conn, CURLOPT_SSL_VERIFYPEER, true);
        curl_setopt($conn, CURLOPT_FRESH_CONNECT,  true);
        curl_setopt($conn, CURLOPT_RETURNTRANSFER, 1);
        $url_get_contents_data = (curl_exec($conn));
        curl_close($conn);
    }elseif(function_exists('file_get_contents')){
        $url_get_contents_data = file_get_contents($url);
    }elseif(function_exists('fopen') && function_exists('stream_get_contents')){
        $handle = fopen ($url, "r");
        $url_get_contents_data = stream_get_contents($handle);
    }else{
        $url_get_contents_data = false;
    }
    return $url_get_contents_data;
} 

$html = url_get_contents("http://linktopage.com");
echo $html;
?>

However one of the website i want to get the price of an item from blocks this method and shows me 'your ip has been banned'. Is there an other way than file_gets_content (same result) and curl (code above) to get a html code from a page ?

If there is a better method to my problem that would be great too. Regards.

Upvotes: 1

Views: 659

Answers (1)

Vika Marquez
Vika Marquez

Reputation: 353

If your IP banned, you should use proxy servers. "cURL" library can work with proxy, set CURLOPT_PROXY and other proxy-options in "curl_setopt" function.

Upvotes: 1

Related Questions