Beispiel #1
0
function curl($url, $referrer = 0, $post = 0, $cookies = 0, $auth = 0, $headersOnly = 0, $debug = 0)
{
    $curl = new Curl_HTTP_Client();
    if ($debug) {
        $curl->debug = 0;
    }
    //$url = 'http://web-sniffer.net/?url='.urlencode($url).'&rawhtml=yes&submit=Submit&http=1.1&gzip=yes&type=GET&uak=1';
    //print '<br><br>URL:'.$url.'<br>';
    //pretend to be IE6 on windows
    $useragent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
    $curl->set_user_agent($useragent);
    //uncomment next two lines if you want to manage cookies
    if ($cookies != 0) {
        $cookies_file = "cookies/cookies.txt";
        $curl->store_cookies($cookies_file);
    }
    //Uncomment next line if you want to set credentials
    if ($auth != 0) {
        $username = $auth[0];
        $password = $auth[1];
        $curl->set_credentials($username, $password);
    }
    if ($headersOnly) {
        $curl->include_response_headers_only();
    }
    //Uncomment next line if you want to set specific referrer
    if ($referrer != 0) {
        $curl->set_referrer($referrer);
        $referrerStr = 'Referer: ' . $str;
    } else {
        //$referrer='Referer: ';
        $referrerStr = '';
    }
    $host = explode('/', $url);
    $host = $host[2];
    //Set Headers
    $headers = array('GET / HTTP/1.1', 'Host: ' . $host, 'Connection: close', 'User-Agent: ' . $useragent, 'Accept-Encoding: gzip', 'Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7', 'Cache-Control: no', 'Accept-Language: de,en;q=0.7,en-us;q=0.3', $referrerStr);
    $curl->set_headers($headers);
    //if you want to send some post data
    //form post data array like this one
    if ($post != 0) {
        $post_data = $post;
        // $post = array('login' => 'pera', 'password' => 'joe', 'other_foo_field' => 'foo_value');
        //and send request to http://www.foo.com/login.php. Result page is stored in $html_data string
        $html_data = $curl->send_post_data($url, $post_data);
    } else {
        $html_data = $curl->fetch_url($url);
    }
    //You can also fetch data from somewhere using get method!
    //Fetch html from url
    //$html_data = $curl->fetch_url("http://www.foo.com/foobar.php?login=pera&password=joe&other_foo_field=foo_value");
    //if you have more than one IP on your server,
    //you can also bind to specific IP address like ...
    //$bind_ip = "192.168.0.1";
    //$curl->fetch_url("http://www.foo.com/login.php", $bind_ip);
    //$html_data = $curl->send_post_data("http://www.foo.com/login.php", $post_data, $bind_ip);
    $curl->close();
    if ($curl->debug || $_REQUEST['debug'] == 1) {
        print '<textarea>' . $html_data . '</textarea>';
        //exit;
    }
    return $html_data;
}