Igor Simic
5 years ago

PHP CURL Class - use proxy


How to use proxy with PHP Curl Cass? In order to use proxy server when making a CURL request with proxy class you have to add CURLOPT_PROXY param in your request.

        public static function CURLgetRequest($url, $data){
             

            $curl = new Curl\Curl();
            $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
            $curl->setOpt(CURLOPT_PROXY, '12.345.678.90:8118'); // IP:port
            $curl->setOpt(CURLOPT_PROXYUSERPWD, 'username:password');
            $curl->setTimeout(2);  
            $getData = $curl->post($url, $data);

            return $getData;
        }