From 19b721d4418fe6ab64555d82dd5eec9c049321bf Mon Sep 17 00:00:00 2001 From: ghost Date: Fri, 15 Sep 2023 02:45:45 +0300 Subject: [PATCH] add curl library --- src/library/curl.php | 96 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/library/curl.php diff --git a/src/library/curl.php b/src/library/curl.php new file mode 100644 index 0000000..c880268 --- /dev/null +++ b/src/library/curl.php @@ -0,0 +1,96 @@ +_connection = curl_init($url); + + if (!empty($post)) + { + curl_setopt($this->_connection, CURLOPT_POST, true); + curl_setopt($this->_connection, CURLOPT_POSTFIELDS, $post); + } + + if ($header) { + curl_setopt($this->_connection, CURLOPT_HEADER, true); + } + + if ($followLocation) { + curl_setopt($this->_connection, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($this->_connection, CURLOPT_MAXREDIRS, $maxRedirects); + } + + curl_setopt($this->_connection, CURLOPT_RETURNTRANSFER, true); + curl_setopt($this->_connection, CURLOPT_CONNECTTIMEOUT, $connectTimeout); + curl_setopt($this->_connection, CURLOPT_TIMEOUT, $connectTimeout); + curl_setopt($this->_connection, CURLOPT_SSL_VERIFYHOST, $sslVerifyHost); + curl_setopt($this->_connection, CURLOPT_SSL_VERIFYPEER, $sslVerifyPeer); + + if ($userAgent) + { + curl_setopt($this->_connection, CURLOPT_USERAGENT, $userAgent); + } + + $this->_response = curl_exec($this->_connection); + } + + public function __destruct() + { + curl_close($this->_connection); + } + + public function getError() + { + if (curl_errno($this->_connection)) + { + return curl_errno($this->_connection); + } + + else + { + return false; + } + } + + public function getCode() + { + return curl_getinfo($this->_connection, CURLINFO_HTTP_CODE); + } + + public function getContentType() + { + return curl_getinfo($this->_connection, CURLINFO_CONTENT_TYPE); + } + + public function getSizeDownload() + { + return curl_getinfo($this->_connection, CURLINFO_SIZE_DOWNLOAD); + } + + public function getSizeRequest() + { + return curl_getinfo($this->_connection, CURLINFO_REQUEST_SIZE); + } + + public function getTotalTime() + { + return curl_getinfo($this->_connection, CURLINFO_TOTAL_TIME_T); + } + + public function getResponse() + { + return $this->_response; + } +} \ No newline at end of file