function get_curl($url, $post=0, $referer=0, $cookie=0, $header=0, $ua=0, $nobody=0, $addheader=0)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$httpheader[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7";
$httpheader[] = "Accept-Encoding: gzip, deflate, br";
$httpheader[] = "Accept-Language: zh-CN,zh;q=0.9";
$httpheader[] = "Connection: close";
if($addheader){
$httpheader = array_merge($httpheader, $addheader);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
if ($post) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
if ($header) {
curl_setopt($ch, CURLOPT_HEADER, true);
}
if ($cookie) {
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}
if($referer){
curl_setopt($ch, CURLOPT_REFERER, $referer);
}
if ($ua) {
curl_setopt($ch, CURLOPT_USERAGENT, $ua);
}
else {
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36");
}
if ($nobody) {
curl_setopt($ch, CURLOPT_NOBODY, 1);
}
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ret = curl_exec($ch);
curl_close($ch);
return $ret;
}
function curlPost($url, $post_data = array(), $timeout = 5, $header = "", $data_type = "") {
$header = empty($header) ? '' : $header;
//支持json数据数据提交
if($data_type == 'json'){
$post_string = json_encode($post_data);
}elseif($data_type == 'array') {
$post_string = $post_data;
}elseif(is_array($post_data)){
$post_string = http_build_query($post_data, '', '&');
}
$ch = curl_init(); // 启动一个CURL会话
curl_setopt($ch, CURLOPT_URL, $url); // 要访问的地址
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查 // https请求 不验证证书和hosts
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
//curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
// curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.54 Safari/537.36');
curl_setopt($ch, CURLOPT_REFERER, 'https://lf.iwebs.ml/');
curl_setopt($ch, CURLOPT_POST, true); // 发送一个常规的Post请求
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); // Post提交的数据包
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // 设置超时限制防止死循环
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_ENCODING, '');//解决网页乱码问题 很重要
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); //模拟的header头
// 打印请求的header信息
$a = curl_getinfo($ch);
$data = curl_exec($ch); //运行 curl,请求网页并返回结果
curl_close($ch); //关闭 curl
return $data;
}
function curlget($url, $timeout =15)
{
$header = array(
"X-FORWARDED-FOR:".rand_ip(),
"CLIENT-IP:".rand_ip(),
"X-Real-IP:".rand_ip(),
"referer: https://lf.iwebs.ml",//模拟来路访问
"Connection: Keep-Alive",//可持久连接、连接重用。。。避免了重新建立连接
"User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36",
"Accept: application/json, text/javascript, */*; q=0.01",
"Accept-Language: zh-CN,zh;q=0.9",
);
$ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36';
$ch = curl_init(); //初始化 curl
curl_setopt($ch, CURLOPT_URL, $url); //要访问网页 URL 地址
curl_setopt($ch, CURLOPT_NOBODY, false); //设定是否输出页面内容
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //返回字符串,而非直接输出到屏幕上
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,10); //连接超时时间,设置为 0,则无限等待
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); //数据传输的最大允许时间超时,设为一小时
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); //HTTP验证方法
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不检查 SSL 证书来源
curl_setopt($ch, CURLOPT_USERAGENT, $ua); // 伪造ua
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //不检查 证书中 SSL 加密算法是否存在
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //跟踪爬取重定向页面
curl_setopt($ch, CURLOPT_AUTOREFERER, true); //当Location:重定向时,自动设置header中的Referer:信息
curl_setopt($ch, CURLOPT_ENCODING, ''); //解决网页乱码问题
curl_setopt($ch, CURLOPT_REFERER, 'https://json.xdys.vip');
//curl_setopt($ch, CURLOPT_REFERER, $_SERVER['HTTP_REFERER']);
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_HEADER,0); //显示头部数据为1 不显示为0
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); //强制协议为1.0
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); //强制使用IPV4协议解析域名
$httpheaders = array();
$httpheaders[] = "Origin:http://{$_SERVER['HTTP_HOST']}"; //模拟浏览器CORS跨域请求
$httpheaders[] = "Content-Type: application/json; charset=utf-8";
$httpheaders[] = "CLIENT-IP: {$_SERVER['HTTP_CLIENT_IP']}";
$httpheaders[] = "X-FORWARDED-FOR: {$_SERVER['HTTP_X_FORWARDED_FOR']}";
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheaders);
$data = curl_exec($ch); //运行 curl,请求网页并返回结果
curl_close($ch); //关闭 curl
return $data;
}
function noDongTaiDaili($url,$action = 'data',$post_data = [],$timeout = 5,$header = "",$data_type = "", $dailikg, $proxyServer)
{
$header = empty($header) ? '' : $header;
//支持json数据数据提交
if ($data_type == 'json') {
$post_string = json_encode($post_data);
} elseif ($data_type == 'array') {
$post_string = $post_data;
} elseif (is_array($post_data)) {
$post_string = http_build_query($post_data, '', '&');
}
$ch = curl_init(); //初始化 curl
curl_setopt($ch, CURLOPT_URL, $url); //要访问网页 URL 地址
curl_setopt($ch, CURLOPT_NOBODY, false); //设定是否输出页面内容
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //返回字符串,而非直接输出到屏幕上
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); //连接超时时间,设置为 0,则无限等待
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); //数据传输的最大允许时间超时,设为一小时
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); //HTTP验证方法
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不检查 SSL 证书来源
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //不检查 证书中 SSL 加密算法是否存在
if ($dailikg) {
curl_setopt($ch, CURLOPT_PROXY, $proxyServer);
}
if(!empty($post_data)){
curl_setopt($ch, CURLOPT_POST, true); // 发送一个常规的Post请求
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); // Post提交的数据包
}
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //跟踪爬取重定向页面
curl_setopt($ch, CURLOPT_AUTOREFERER, true); //当Location:重定向时,自动设置header中的Referer:信息
curl_setopt($ch, CURLOPT_ENCODING, 'gzip'); //解决网页乱码问题
// curl_setopt($ch, CURLOPT_REFERER, $pc);
if (!empty($header)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
}
curl_setopt($ch, CURLOPT_USERAGENT, $pc);
curl_setopt($ch, CURLOPT_HEADER, false); //显示头部数据为1 不显示为0
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); //强制协议为1.0
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); //强制使用IPV4协议解析域名
try {
$data = curl_exec($ch); //运行 curl,请求网页并返回结果
}catch (Exception $e){
echo $e->getMessage();
}
if ($action == "code" || $action == "header") {
$data = curl_getinfo($ch);
}else if ($action == "datacode" || $action == "dataheader" || $action == "codedata") {
$datacode = curl_getinfo($ch);
$arr['header']=$datacode;
$arr['code']=$datacode;
$arr['data']=$data;
curl_close($ch); //关闭 curl
return $arr;
}
curl_close($ch); //关闭 curl
return $data;
}
function rand_ip(){
$ip_long = array(
array('607649792', '608174079'), //36.56.0.0-36.63.255.255
array('975044608', '977272831'), //58.30.0.0-58.63.255.255
array('999751680', '999784447'), //59.151.0.0-59.151.127.255
array('1019346944', '1019478015'), //60.194.0.0-60.195.255.255
array('1038614528', '1039007743'), //61.232.0.0-61.237.255.255
array('1783627776', '1784676351'), //106.80.0.0-106.95.255.255
array('1947009024', '1947074559'), //116.13.0.0-116.13.255.255
array('1987051520', '1988034559'), //118.112.0.0-118.126.255.255
array('2035023872', '2035154943'), //121.76.0.0-121.77.255.255
array('2078801920', '2079064063'), //123.232.0.0-123.235.255.255
array('-1950089216', '-1948778497'), //139.196.0.0-139.215.255.255
array('-1425539072', '-1425014785'), //171.8.0.0-171.15.255.255
array('-1236271104', '-1235419137'), //182.80.0.0-182.92.255.255
array('-770113536', '-768606209'), //210.25.0.0-210.47.255.255
array('-569376768', '-564133889'), //222.16.0.0-222.95.255.255
);
$rand_key = mt_rand(0, 14);
$huoduan_ip= long2ip(mt_rand($ip_long[$rand_key][0], $ip_long[$rand_key][1]));
return $huoduan_ip;
}
扫描二维码,在手机上阅读
版权说明
文章采用: 《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权。版权声明:未标注转载均为本站原创,转载时请以链接形式注明文章出处。如有侵权、不妥之处,请联系站长删除。敬请谅解!