I am creating a custom helper in ./application/helpers however i am getting this error
Unable to load requested file helpers/curl_helper
This is the code in my helper file:
function send(array $request, $url, $method)
{
//Validating if the required extensions are installed or not
if( !function_exists('json_encode') ) return false;
if( !function_exists('curl_init') ) return false;
//Converting the array into required json format
$request = json_encode($request);
//Setting header required for requests
$header[] = "Content-type: application/json";
$header[] = "Content-length: ".strlen($request) . "\r\n";
//If the request method is get append the data into requests header
if( $method == 'GET' or $method == 'get' ) $header[] = $request;
//Initializing curl
$ch = curl_init();
//Setting curl options for request
curl_setopt( $ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, $method );
//If the request method is post add the data we need to enable post
//request and define the data in post fields
if( $method == 'POST' or $method == 'post' ) {
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $request);
}
//Executing the curl request and storing the result in a variable
$result = curl_exec( $ch );
//Closing curl conneciton
curl_close($ch);
return json_decode($result);
}
And i am loading it in my library like:
$this->loader =& get_instance();
$this->loader->load->helper('curl');
Tell me where i am doing wrong?
UPDATE:
After trying too many things when i put the function in the same library where i want to use i found that there is an error in the line
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header );
when i comment this line function works fine. I dont know where is the error please help me. And as far as i think this is the reason for loader error.