万能PHP Curl封装类,适合多个场景,调用方便!

一个博主自己写的PHP Curl封装,适合多个场景,调用方便!

 $matches, "body" => $body, "header" => $header, 'code' => curl_getinfo($ch, CURLINFO_HTTP_CODE),
        ];
        curl_close($ch);
        return $ret;
    }
    $ret = curl_exec($ch);
    if (isset($paras['loadurl'])) {
        $Headers = curl_getinfo($ch);
        if (isset($Headers['redirect_url'])) {
            $ret = $Headers['redirect_url'];
        } else {
            $ret = false;
        }
    }
    curl_close($ch);
    return $ret;
}

使用示例

Get

echo teacher_curl("https://api.oioweb.cn/api/beian.php?url=qq.com");

Post

echo teacher_curl("https://api.oioweb.cn/api/beian.php",[
    'post'=>[
        'url'=>'qq.com'
    ]
]);

文件上传

echo teacher_curl("https://api.oioweb.cn/api/beian.php?url=qq.com",[
    'post'=>[
        'file'=>new CURLFile(realpath("Curl.jpg"))
    ]
]);

设置请求头

echo teacher_curl("https://api.oioweb.cn/api/beian.php?url=qq.com",[
    'Header'=>[
        'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
accept-encoding: gzip, deflate, br
accept-language: zh-CN,zh;q=0.9
cache-control: max-age=0'
    ]
]);

*模拟UseaAgent

echo teacher_curl("https://api.oioweb.cn/api/beian.php?url=qq.com",[
    'ua'=>'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'
]);

携带Cookie

echo teacher_curl("https://api.oioweb.cn/api/beian.php?url=qq.com",[
    'cookie'=>'cookie内容'
]);

你可能感兴趣的:(phpcurl)