How to use cUrl data to get data in CodeIgniter

I would like to ask about the cUrl application on CodeIgniter.
Where should I put the cURL encoding, is it in view or controller mode?


source to share

2 answers

It will be ok in the controller, like

`function index()
    // Get cURL resource
    $curl = curl_init();
    // Set some options - we are passing in a useragent too here
    curl_setopt_array($curl, array(
        CURLOPT_URL => 'http://localhost/ci_paginationv2-
        CURLOPT_USERAGENT => 'Codular Sample cURL Request'
    // Send the request & save response to $resp
    $resp = curl_exec($curl);
    // Close request to clear up some resources

    echo $resp;





The best practice would be to put your logic in the controller itself according to the code conventions, then process the response itself (if needed) and then render the view for it (if the data needs to be viewed). Please comment if anything is unclear.

Click here to see more about it



All Articles