PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Dragan Dinic   Curl HTTP Client   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example of Usage
Class: Curl HTTP Client
HTTP client using the PHP Curl library
Author: By
Last change:
Date: 18 years ago
Size: 1,553 bytes
 

Contents

Class file image Download
<?php
/**
 * @version $Id$
 * @package dinke.net
 * @copyright &copy; 2005 Dinke.net
 * @author Dragan Dinic <dragan@dinke.net>
 */

require_once("curl_http_client.php");

$curl = &new Curl_HTTP_Client();

//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
//$cookies_file = "/tmp/cookies.txt";
//$curl->store_cookies($cookies_file);

//Uncomment next line if you want to set credentials
//$curl->set_credentials($username, $password);

//Uncomment next line if you want to set specific referrer
//$curl->set_referrer("http://my.referrer.url");

//if you want to send some post data
//form post data array like this one
$post_data = 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("http://www.foo.com/login.php", $post_data);
 
//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);
?>