CodeIgniter Curl library

CodeIgniter Curl library 是將php的curl function 寫成一個library方便於在 CodeIgniter 上使用,雖然可以直接在CodeIgniter裡面寫curl function,但是Curl library已經打包好了不需要重覆寫相同的程式,另外後面是以登入plurk為範例,所以必須先取得 plurk api key喔!

準備

1. 下載 curl libraries 並放置 libraries 資料夾裡

2. 設定自動載入 curl libraries

    // 修改 config/autoload.php
    $autoload['libraries'] = array('curl');

範例

一 登入 PLURK

1
2
$responce = $this->curl->simple_post('http://www.plurk.com/API/Users/login', array('api_key'=>'xxxx','username'=>'xxxx','password'=>'xxxx'));
print_r(json_decode($responce));

二 登入 PLURK save cookie

1
2
3
4
5
6
7
8
9
10
$_options = array(
    CURLOPT_COOKIESESSION => true,
    CURLOPT_COOKIEFILE => './cache/cookie',
    CURLOPT_COOKIEJAR => './cache/cookie',
    CURLOPT_USERAGENT => "php-plurk-api agent"
);
$this->curl->create('http://www.plurk.com/API/Users/login');
$this->curl->options($_options);
$this->curl->post(array('api_key'=>'xxxx','username'=>'xxxx','password'=>'xxxx'));
print_r(json_decode($this->curl->execute()));

參考資料:

Related Posts with Thumbnails

相關文章

發表迴響

您的電子郵件位址並不會被公開。 必要欄位標記為 *

*

您可以使用這些 HTML 標籤與屬性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>