Curl GET using Codeigniter

Published Jan 25, 2017
Curl GET using Codeigniter
  class process extends CI_Controller {

  public function __construct()
    // created the construct so that the helpers, libraries, models can be loaded all through this controller
        $this->refcode = $this->session->userdata('refcode');

  public function index()
      $secretKey = "sk_test_1234567";

      $url = "" . $this->refcode;

      // append the header putting the secret key and hash

      $request_headers = array();
      $request_headers[] = 'Authorization: Bearer ' . $secretKey;
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_TIMEOUT, 60);
      curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      $data = curl_exec($ch);

      if (curl_errno($ch))
        print "Error: " . curl_error($ch);
        // Show me the result

        $transaction = json_decode($data, TRUE);



Discover and read more posts from Oluwaseye Ogunkoya
get started
Enjoy this post?

Leave a like and comment for Oluwaseye

Oluwaseye Ogunkoya
4 months ago

@Rogert You’re welcome

Rogert Castillo
4 months ago

Thanks friend, your code was very useful for me.

Get curated posts in your inbox

Read more posts to become a better developer