我正在使用cURL代理从服务器获取文件,该代码显示网页上的文件文本未下载,但是当我请求www.example.com/download.php
时,我需要开始下载文件。
$proxy = '1.1.1.1:1212'; // <-- Replace 1.1.1.1:1212 with your proxy IP:PORT
$url = 'http://www.ipcheckit.com';
$content = getUrlContents($url, $proxy);
print $content;
$content = getUrlContents($url, $proxy);
print$content;
function getUrlContents($url, $proxy = NULL, $post_data = NULL, $timeout = 30, $userpass = NULL) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
if ($post_data !== NULL) {
curl_setopt($curl, CURLOPT_POST,FALSE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
}
if ($proxy != NULL) {
curl_setopt($curl, CURLOPT_PROXY, $proxy);
}
if ($userpass != NULL) {
curl_setopt($curl, CURLOPT_USERPWD, $userpass);
}
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_MAXREDIRS, 5);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
$contents = curl_exec($curl);
curl_close($curl);
return $contents;
}
?>