kenvix / curl
A very lite and high compatibility but powerful curl class(especially you're processing http headers and cookies). No dependence.
1.0
2018-09-02 04:10 UTC
This package is auto-updated.
Last update: 2025-07-11 02:14:39 UTC
README
A very lite and high compatibility but powerful curl class(especially you're processing http headers and cookies). No dependence.
Usage
Basical HTTP request
Get
$curl = new \Kenvix\curl\curl("https://bing.com/"); $curl->get(); //string response
Or:
\Kenvix\curl\curl::xget("https://bing.com/");
You can't:
echo new \Kenvix\curl\curl("https://bing.com/"); //Will always print a description
POST
$curl = new \Kenvix\curl\curl("https://bing.com/"); $curl->post([ //something to post 'a' => 'foo', 'b' => 'excited' ]); //string response
HEAD
$curl = new \Kenvix\curl\curl("https://www.bing.com/"); $curl->head(); //array response
Response:
array (size=9)
'Cache-Control' => string 'private, max-age=0' (length=18)
'Transfer-Encoding' => string 'chunked' (length=7)
'Content-Type' => string 'text/html; charset=utf-8' (length=24)
'Vary' => string 'Accept-Encoding' (length=15)
...
Get Cookies
$curl = new \Kenvix\curl\curl("https://www.bing.com/"); $curl->head(); $curl->getCookies(); //array
Response:
Array
(
[SRCHD] => Array
(
[key] => SRCHD
[value] => AF=NOFORM
[domain] => .bing.com
[expires] => Sat, 22-Aug-2020 10:56:24 GMT
[path] => /
)
[_EDGE_V] => Array
(
[key] => _EDGE_V
[value] => 1
[path] => /
[httponly] => 1
[expires] => Mon, 16-Sep-2019 10:56:25 GMT
[domain] => bing.com
)
...
Customize request headers
$curl = new \Kenvix\curl\curl("https://www.bing.com/",array('User-Agent: chrome', 'Referer: https://kenvix.com'));
or
$curl->setHeaders(array('User-Agent: chrome', 'Referer: https://kenvix.com'));
Other
$curl->put($data); $curl->delete($data);
Do not follow redirect
NOTICE: CURLOPT_FOLLOWLOCATION HAS ALREADY BEEN SET TO false!!!
get() post() head() delete() put() provide a parameter to allow you to do this.
$curl->get(false); $curl->post([...], false);
Useful Methods
addCookie($ck)
Add a cookie:
$curl->addCookie('yes=sir');
Add cookies:
$curl->addCookie([ 'a' => 'foo', 'b' => 'excited' ]);
getHTTPCode()
returns http code
getRedirectNum()
returns
Common Methods
execRaw()
returns raw result
readCookies(array $setcookie)
STATIC
parse cookies into array
parseCookieKeyValue($str)
STATIC
getConnection()
Returns curl connection
setRequestMethod($method)
A custom request method to use instead of "GET" or "HEAD" when doing a HTTP request.