Answer the question
In order to leave comments, you need to log in
Does cURL PHP require any special proxies?
I bought a proxy from a certain site. 4 pieces. All private, with login and password. I have a PHP code that fetches a page using cURL (I took ip-api.com/json/ for testing). The checker on their website says that all 4 proxies are valid. My code is only able to work with one of the four. On the other three, instead of the page, it gives out "407 Proxy Authentication Required". This is fine? Is it the proxy or the code? Or maybe some special proxies are needed for cURL?
class mycurl {
protected $_url;
protected $_headers = [];
protected $_post;
protected $_postFields;
protected $_proxy;
protected $_proxyAddr;
protected $_proxyPort;
protected $_proxyUserPass;
protected $_useragent = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36';
protected $_referer = "https://www.google.com";
protected $_timeout = 10;
protected $_maxRedirects = 4;
protected $_followlocation = true;
protected $_includeHeader = true;
protected $_info;
public function __construct($url,
$headers = null,
$post = false,
$postFields = null,
$isproxy = false,
$proxy = null,
$includeHeader = true) {
$this->_url = $url;
($headers == null) ? $this->_headers = [] : $this->_headers = $headers;
$this->_post = $post;
$this->_postFields = $postFields;
$this->_proxy = $isproxy;
$this->_includeHeader = $includeHeader;
if ($isproxy) {
$proxy_arr = explode(":", $proxy);
if (count($proxy_arr) == 4) {
$this->_proxyAddr = $proxy_arr[0];
$this->_proxyPort = $proxy_arr[1];
$this->_proxyUserPass = $proxy_arr[2] . ":" . $proxy_arr[3];
}
else {
$this->_proxyAddr = $proxy_arr[0];
$this->_proxyPort = $proxy_arr[1];
$this->_proxyUserPass = null;
}
}
else {
$this->_proxyAddr = null;
$this->_proxyPort = null;
$this->_proxyUserPass = null;
}
}
public function GetResponse() {
$s = curl_init();
curl_setopt($s, CURLOPT_RETURNTRANSFER, true);
curl_setopt($s, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($s, CURLOPT_URL, $this->_url);
curl_setopt($s, CURLOPT_HTTPHEADER, $this->_headers);
curl_setopt($s, CURLOPT_TIMEOUT, $this->_timeout);
curl_setopt($s, CURLOPT_MAXREDIRS, $this->_maxRedirects);
curl_setopt($s, CURLOPT_FOLLOWLOCATION, $this->_followlocation);
if ($this->_post)
{
curl_setopt($s, CURLOPT_POST, true);
curl_setopt($s, CURLOPT_POSTFIELDS, $this->_postFields);
}
if ($this->_proxy) {
curl_setopt($s, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($s, CURLOPT_HTTPPROXYTUNNEL, 0);
curl_setopt($s, CURLOPT_PROXY, $this->_proxyAddr);
curl_setopt($s, CURLOPT_PROXYPORT, $this->_proxyPort);
if ($this->_proxyUserPass != null) {
curl_setopt($s, CURLOPT_PROXYUSERPWD, $this->_proxyUserPass);
curl_setopt($s, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
}
}
if ($this->_includeHeader) curl_setopt($s, CURLOPT_HEADER,true);
curl_setopt($s, CURLOPT_USERAGENT, $this->_useragent);
curl_setopt($s, CURLOPT_REFERER, $this->_referer);
$response = curl_exec($s);
$this->_info = curl_getinfo($s);
curl_close($s);
return $response;
}
public function GetInfo() {
return $this->_info;
}
}
$MyCURL = new mycurl(
"http://ip-api.com/json/",
false,
false,
null,
true,
GetProxy(),
true
);
$result = $MyCURL->GetResponse();
echo $result;
Answer the question
In order to leave comments, you need to log in
Are you sure you pass the login pass from a specific one and not from the first one?
depending on the type of proxy - different parameters.
HTTP proxy:
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTPS);
curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_pass);
Thank you all, I made a crutch through Python requests. For some reason it works with a proxy adequately
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question