Zebra_cURL::proxy PHP Method

proxy() public method

the callback function to be executed for each and every request, as soon as a request finishes function mycallback($result) { everything went well at cURL level if ($result->response[1] == CURLE_OK) { if server responded with code 200 (meaning that everything went well) see http://httpstatus.es/ for a list of possible response codes if ($result->info['http_code'] == 200) { see all the returned data print_r('
');
            print_r($result);
show the server's response code
        } else die('Server responded with code ' . $result->info['http_code']);
something went wrong
($result still contains all data that could be gathered)
    } else die('cURL responded with: ' . $result->response[0]);

}
include the Zebra_cURL library
require 'path/to/Zebra_cURL';
instantiate the class
$curl = new Zebra_cURL();
connect to a proxy server
(that's a random one i got from http://www.hidemyass.com/proxy-list/)
$curl->proxy('187.63.32.250', '3128');
fetch a page
$curl->get('http://www.somewebsite.com/', 'mycallback');
        
public proxy ( string $proxy, string $port = 80, string $username = '', string $password = '' ) : void
$proxy string The HTTP proxy to tunnel requests through. Can be an URL or an IP address. This option can also be set using the {@link option} method and setting CURLOPT_PROXY option to the desired value. Setting this argument to FALSE will "unset" all the proxy-related options. @param string $port (Optional) The port number of the proxy to connect to. Default is 80. This option can also be set using the {@link option} method and setting CURLOPT_PROXYPORT option to the desired value. @param string $username (Optional) The username to be used for the connection to the proxy (if required by the proxy) Default is "" (an empty string) The username and the password can also be set using the {@link option} method and setting CURLOPT_PROXYUSERPWD option to the desired value formatted like [username]:[password]. . @param string $password (Optional) The password to be used for the connection to the proxy (if required by the proxy) Default is "" (an empty string) The username and the password can also be set using the {@link option} method and setting CURLOPT_PROXYUSERPWD option to the desired value formatted like [username]:[password]. . @return void
$port string
$username string
$password string
return void
    public function proxy($proxy, $port = 80, $username = '', $password = '')
    {
        // if not disabled
        if ($proxy) {
            // set the required options
            $this->option(array(CURLOPT_HTTPPROXYTUNNEL => 1, CURLOPT_PROXY => $proxy, CURLOPT_PROXYPORT => $port));
            // if a username is also specified
            if ($username != '') {
                // set authentication values
                $this->option(CURLOPT_PROXYUSERPWD, $username . ':' . $password);
            }
            // if disabled
        } else {
            // unset proxy-related options
            $this->option(array(CURLOPT_HTTPPROXYTUNNEL => null, CURLOPT_PROXY => null, CURLOPT_PROXYPORT => null));
        }
    }