Ridho Habi Putra
Ridho Habi Putra

Reputation: 11

Using Curl in codeigniter like this

How to use cURL in codeigniter? I have API access like this, and i want use in codeigniter.

<?php
$url = 'http://portalpulsa.com/api/connect/';

$header = array(
    'portal-userid: userid',
    'portal-key: key',
    'portal-secret: secretkey',
);

$data = array(
    'inquiry' => 'S', // konstan
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

$result = curl_exec($ch);

echo $result;

Upvotes: 1

Views: 2010

Answers (1)

BSB
BSB

Reputation: 2468

You can use CURL in codeigniter as you use it in core PHP. There is no official CURL library/stranded for codeigniter.

If you have requirement to use CURL multiple times in your project, You can write it as a function in helper class.

Upvotes: 2

Related Questions