GET
public static function curl($url)
{
//初始化
$curl = curl_init();
//请求url
curl_setopt($curl, CURLOPT_URL, $url);
//设定不输出页面内容
curl_setopt($curl, CURLOPT_HEADER, 0);
//要转存--1为手动输出0自动输出
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//设置user-agent 在HTTP请求中包含一个"user-agent"头的字符串
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
//验证SSL
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$rtn = curl_exec($curl);
//没错误
if (!curl_error($curl)) {
return $rtn;
//有错误
} else {
return curl_error($curl);
}
}