April 20, 2008 by Alex Polski

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');

Download Curl library 1.1 for CodeIgniter

Share and Enjoy:
  • del.icio.us
  • Digg
  • Reddit
  • Ma.gnolia
  • Technorati
  • Propeller
  • Facebook
  • StumbleUpon
  • Furl
  • blogmarks
  • Google
  • YahooMyWeb
  • E-mail this story to a friend!
This entry was posted on Sunday, April 20, 2008 at 7:20 am and is filed under CodeIgniter, Curl Library, Free downloads. You can leave a response, or trackback from your own site.

Related posts

« Finally, Mass PageRank Checker tool!

How to check Alexa Rank in PHP »



4 Responses to “Curl library 1.1 for CodeIgniter”

mambe nanje
Posted on May 20th, 2008 at 6:40 am

I would like to use curl to login to a site eg http://www.mail.yahoo.com and also maintain the cookies so I can use curl to visit other areas of the site for say grab contacts.
can you please give me a sample tutorial on how to do that, please it will help me learn curl faster.
I am interested in CURL and I am very good in Codeigniter but as for curl I have not experience - total new bee

Alex Polski
Posted on May 20th, 2008 at 1:05 pm

mambe nanje, cookies handling is not supported by the current version of Curl Library for CodeIgniter now, but will be implemented soon I hope. Here some good tutorials you can read:
http://www.weberdev.com/get_example-4277.html
http://www.weberdev.com/get_example-4555.html

Thomas
Posted on October 9th, 2008 at 2:38 am

I realy enjoy de idea!
If I can join to the project I will be happy to help..

add me on MSN.. let’s talk about it…
;D

Matt
Posted on December 3rd, 2008 at 10:23 am

Thanks for this project. Most useful! Let me know if you need help on the project.

Leave a Reply