CURL函数的GET和POST方式的两种写法(实现ajax跨域调用)

POST请求

function curl_post($url='',$postdata='',$options=array()){
$ch=curl_init($url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,);
curl_setopt($ch,CURLOPT_POST,);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_TIMEOUT, );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
if(!empty($options)){
curl_setopt_array($ch, $options);
}
$data=curl_exec($ch);
curl_close($ch);
return $data;
}

GET请求

function curl_get($url='',$options=array()){
$ch=curl_init($url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,);
curl_setopt($ch,CURLOPT_TIMEOUT,);
if(!empty($options)){
curl_setopt_array($ch,$options);
}
$data=curl_exec($ch);
curl_close($ch);
return $data;
}
ex:

    

$sess_id=$_POST['sess_id'];
$arr=curl_get("http://www.zb12351.com/mapi/index.php?r_type=1&ctl=uc_account&act=index&sess_id=".$sess_id);
echo $arr;


上一篇:sublime text3快速生成html头部信息


下一篇:linux 查看用户所在组(groups指令的使用) 含实例