Archive for the ‘Curl Library’ Category
May 14, 2008 by Alex Polski | 3 Comments »
Bugfixes in Curl library for CodeIgniter
Dear friends! There were two bugs fixed in Curl library for CodeIgniter:
- Posssible returning of incorrect URL by abs_url function
- Possible incorrect value in $url variable
Download updated Curl library for CodeIgniter, v. 1.1.1 (zip, 4kb)
April 20, 2008 by Alex Polski | 4 Comments »
Curl library 1.1 for CodeIgniter
I continue to develop Curl library for CodeIgniter and today’s blog post is about the new version. What’s new in this release?
First of all, request and response headers are supported now. You may specify your own request header in http_get and http_post methods:
$headers = array(
'Authorization: AuthSub token="' . $_POST['token'] . '"',
'X-Google-Key: key=' . $developerKey,
'Content-Type: application/atom+xml'
);
$this->curl->http_post($url, $postfields, $headers);
As for response headers, you have an access to them now through the $headers variable:
echo $this->curl->headers;
One more feature that I want to tell you is automatic redirect support. Look at this code:
$this->curl->http_get('http://google.com');
Curl library will parse headers (or use CURLOPT_FOLLOWLOCATION curl option if possible) and automatically redirect to http://www.google.com.
To know what’s the final URL of HTTP GET/POST operation you can use $url variable:
echo $this->curl->url;
If for some reasons you do not want to use automatic redirect feature, use this code:
$this->curl->open(array('follow_location' => false)); // during initialization
// or
$this->curl->follow_location = false;
And the last thing I want to tell is a small bonus: abs_url function which will help you to convert relative URL to absolute one.
$absolute_url = $this->curl->abs_url('../test.html', 'http://example.com/path/to');
April 13, 2008 by Alex Polski | 4 Comments »
Curl library for CodeIgniter
So, let’s continue to develop Mass PageRank Checker tool. I will use CodeIgniter (CI) PHP framework for it. It’s really simple and very powerful thing. But first I need Curl library for CI to make easier working with HTTP queries.
In brief, the library must do the following things:
- Send HTTP GET/POST requests and receive HTTP responses.
- Get information about queries like HTTP error code, total time for operation, number of sent/received bytes for operation, etc.
- Handle the errors.
I just wrote this library, you can download it here.
To use it just copy Curl.php to CI’s system/application/libraries folder, curl_lang.php to CI’s system/application/language/english folder and load it from your controllers:
$this->load->library('curl');
For example let’s simulate the search in Google:
$keyword = 'travel';
$this->load->library('curl');
$this->curl->open();
$content = $this->curl->http_get("http://www.google.com/search?q=$keyword");
$this->curl->close();
echo $content;
This is very simple example. At this moment the library has not powerful features. Here the list of what you can do and how you can do using Curl library:
- Set additional options like User-Agent (MSIE 7.0 by default), timeout for operations in seconds (30 by default).
$this->curl->open(array('user_agent' => 'CURL library', 'timeout' => 60));
- Send HTTP GET query and get the content. Setting $headers_only = TRUE will cause you receive HTTP headers only. You can specify additional HTTP headers in $headers variable.
function http_get($url, $headers = array(), $headers_only = FALSE)
- Send HTTP POST query and get the content. POST parameters must be specified in $fields variable like ‘a=1&b=2&str=test%20example’
function http_post($url, $fields, $headers = array(), $headers_only = FALSE)
- There are a few functions for getting different information about query
function get_http_code()
function get_total_time()
function get_bytes_uploaded()
function get_bytes_downloaded()
function get_speed_upload()
function get_speed_download()
In the future I’m planning to add the following features to library: referer and autoreferer support, cookies, proxies, authorization, follow location feature, caching, file uploading, additional headers and may be some more.






















