diff --git a/KBBIModel.php b/KBBIModel.php index 3341867..cfeb72d 100644 --- a/KBBIModel.php +++ b/KBBIModel.php @@ -20,7 +20,12 @@ private function _fetchHtml($word) curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // Disable SSL host verification curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disable SSL peer verification - curl_setopt($ch, CURLOPT_TIMEOUT, 60); + curl_setopt($ch, CURLOPT_USERAGENT, 'Localhost'); + curl_setopt($ch, CURLOPT_HTTPHEADER, ['X-Forwarded-For: 127.0.0.1']); + curl_setopt($ch, CURLOPT_TIMEOUT, 20); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); + curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); + curl_setopt($ch, CURLOPT_MAXREDIRS, 3); $response = curl_exec($ch); @@ -43,7 +48,12 @@ private function _request__KBBI_API_Zhirrr($word) curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // Disable SSL host verification curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Disable SSL peer verification - curl_setopt($ch, CURLOPT_TIMEOUT, 60); + curl_setopt($ch, CURLOPT_USERAGENT, 'Localhost'); + curl_setopt($ch, CURLOPT_HTTPHEADER, ['X-Forwarded-For: 127.0.0.1']); + curl_setopt($ch, CURLOPT_TIMEOUT, 20); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); + curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); + curl_setopt($ch, CURLOPT_MAXREDIRS, 3); $response = curl_exec($ch); @@ -319,15 +329,14 @@ public function searchWord($word) return $_KBBI_official; } } catch (\Exception $e) { + // ZHIRRR + $_KBBI_byZhirrr = $this->_KBBI_byZhirrr($word); + if(count($_KBBI_byZhirrr)) + { + return $_KBBI_byZhirrr; + } // Log the error message or handle it as needed - error_log("Official API error: " . $e->getMessage()); - } - - // ZHIRRR - $_KBBI_byZhirrr = $this->_KBBI_byZhirrr($word); - if(count($_KBBI_byZhirrr)) - { - return $_KBBI_byZhirrr; + // error_log("Official API error: " . $e->getMessage()); } return false;