Skip to content

Php class to make simple curl request. Can use as code igniter library or as php class.

License

Notifications You must be signed in to change notification settings

geronimo794/php-simple-curl-class

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Simple Curl Class

Version 1.0.0

Php class to make simple curl request. Can use as code igniter library or as php class.

Geting started

- As PHP Class

PHP

Step 1 : Download the curl class here here

Step 2 : Include or require the curl class in your php file

require('Curl.php');

Step 3 : Create object from curl class

$my_curl = new Curl();

Step 4 : Set the url of curl request

$my_curl->setUrl('https://api.instagram.com/v1/media/shortcode/BLLZnwjAeEm');

Step 5 : Set the GET/POST parameter to send via curl

$my_curl->setGetData('access_token', 'abxcsdfsdfasdasd');
$my_curl->setPostData('private_key', 'fgxftfsadfsadsad');

OR

$var_to_send = array(
    'access_token' => 'abxcsdfsdfasdasd',
    'private_key' => 'fgxftfsadfsadsad'
);
$my_curl->setGetData($var_to_send);
$my_curl->setPostData($var_to_send);

Step 6 : Set the user_agent of curl

$my_curl->setUserAgent('Maybe mozilla');

Step 7 : Get the curl response

$curl_respon = $my_curl->getResponse();

- As Code Igniter Library

PHP

Step 1 : Download the curl class here here

Step 2 : Put the class file to Code Igniter library Getting Started 1

Step 3 : Load curl library in your controller

$this->load->library('curl');

Step 4 : Set the url of curl request

$this->curl->setUrl('https://api.instagram.com/v1/media/shortcode/BLLZnwjAeEm');

Step 5 : Set the GET/POST parameter to send via curl

$this->curl->setGetData('access_token', 'abxcsdfsdfasdasd');
$this->curl->setPostData('private_key', 'fgxftfsadfsadsad');

OR

$var_to_send = array(
    'access_token' => 'abxcsdfsdfasdasd',
    'private_key' => 'fgxftfsadfsadsad'
);
$this->curl->setGetData($var_to_send);
$this->curl->setPostData($var_to_send);

Step 6 : Set the user_agent of curl

$this->curl->setUserAgent('Maybe mozilla');

Step 7 : Get the curl response

$curl_respon = $this->curl->getResponse();

Avaible methods

  • clear() : Clear all the given setting to curl object
  • setUrl( $url ) : Set the url of curl request
  • setUserAgent( $userAgent ) : Set useragent
  • setPostData( $name, $value ) : Set the post data
  • setPostData( array( $name => $value ) ) : Set the post data
  • setGetData( $name, $value ) : Set the get data
  • setGetData( array( $name => $value ) ) : Set the get data
  • getResponse() : Get response from curl
  • setOption( array( CURL_OPT => CURL_OPT_VAL ) ) (06-12-2016) : Set the additional value for curl options with array
  • setOption( CURL_OPT, CURL_OPT_VAL ) (06-12-2016) : Set the additional value for curl options with single option and value New method Version 1.2.0
  • setHeaderData( array( $name => $value ) ) : Set header data for the curl request with array
  • setHeaderData( $name, $value ) : Set header data for the curl request with name and value of header data
  • setBody( $requestBody ) : Set the body of the curl request, it's usefull when you want to send json data through request body
  • setRequestMethod( $requestMethod ) : Set curl request method it can be GET, POST, PUT, DELETE
  • getInstance() : Get the current instance of the curl for the multiple curl request
  • getResponseMultiInit( $curlInstance = [] ) : Its use for curl multiple instance initiation request, so you can multiple curl request at once

Changelogs

Version 1.0.0

  • setData, setUrl, setUserAgent, clear, getResponse.

Version 1.0.1 (06-12-2012)

  • Add new method setOption.

Version 1.2.0 (24-03-2018)

  • Add new method setHeaderData, setBody, setRequestMethod, getInstance, and getResponseMultiInit.

About

Php class to make simple curl request. Can use as code igniter library or as php class.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages