Library cURL Codeigniter

Library cURL Codeigniter

Apa sih cURL

cURL adalah sebuah program/library untuk mengakses file melalui sebuah url. cURL sudah support banyak protokol seperti FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS dan FILE. Sebenarnya cURL adalah sebuah program command line di unix, tetapi sekarang sudah di support oleh php (menjadi extension php).

Keunggulan Curl

Kenapa cURL? bukankah kita juga menggunakan perintah bawaan php seperti file, readfile, file_get_content untuk mengakses url? iya kita bisa mendapat kan content dari sebuah url dengn perintah tersebut tetapi ada batasan di error handling, header, authentication, post form, upload file.

Library Curl untuk codeigniter

Sebelum memluai penggunaan curl sebagai library codeigniter, sebaiknya kita mengenali carai penggunaan cUrl terlebih dahulu. Sebuah request curl ternisi atas 4 steo utama yaitu:

  1. Initialize: tahap inisisalisasi bertujuan membentuk sebuah curl handle menggunakan curl_init()
  2. Set Options: Mengeset opsi2 yang dibutuh kan spt header, dan paramter lainnya
  3. Execute dan Fetch Result Mengirimkan request ke server
  4. Clear curl handler dengan perintah curl_close()

untuk mempermudah penggunaan maka fungsi curl tersebut dibungkus dan dapat didownload di link berikut

Download

Contoh penggunaan library CURL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
 
class Contoh extends Controller {
 
	function Contoh()
	{
		parent::Controller();	
	}
 
	function index()
	{
		$this->load->library('Curl');
		$google_login_url = "https://www.google.com/accounts/ClientLogin";
		$contact_url = 'http://www.google.com/m8/feeds/contacts/default/full?max-results=100';
		$param = array(
			"accountType" => "GOOGLE",
			"Email" => 'xibnoe',
			"Passwd" => 'PASSWORD GW',
			"service" => "cp",
			"source" => "Webwoork/1.0"
		);
 
		$out = $this->curl->post($google_login_url,$param);
                var_dump($out);
     }
 
     function google()
     {
		$this->load->library('Curl');
		echo $this->curl->get('http://google.com')
	}
}

Artikel yang berhubungan

About ibnoe
Hi, my name is Ibnu Daqiqil Id and I’m an indonesian Web Developer. I love creating simple, unique and easy-to-use web application and what most counts for me is to work with people who are passionate about what they do.

2 Responses to “Library cURL Codeigniter”

  1. CAHYO says:

    Thanks


Leave a Reply

Tags

, , ,

Postingan Terbaru

Copyright © 2010 Tutorial PHP Jquery Codeigniter Ajax javascript