PHP CURL模拟GET及POST函数代码
更新时间:2010年04月25日 15:15:45 作者:
PHP CURL模拟GET及POST函数代码,需要的朋友可以参考下。
复制代码 代码如下:
<?php
function vcurl($url, $post = '', $cookie = '', $cookiejar = '', $referer = ''){
$tmpInfo = '';
$cookiepath = getcwd().'./'.$cookiejar;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
if($referer) {
curl_setopt($curl, CURLOPT_REFERER, $referer);
} else {
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
}
if($post) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
}
if($cookie) {
curl_setopt($curl, CURLOPT_COOKIE, $cookie);
}
if($cookiejar) {
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookiepath);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiepath);
}
//curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 100);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$tmpInfo = curl_exec($curl);
if (curl_errno($curl)) {
echo '<pre><b>错误:</b><br />'.curl_error($curl);
}
curl_close($curl);
return $tmpInfo;
}
?>
您可能感兴趣的文章:
- PHP中使用cURL实现Get和Post请求的方法
- php中使用Curl、socket、file_get_contents三种方法POST提交数据
- php的curl实现get和post的代码
- PHP中的使用curl发送请求(GET请求和POST请求)
- PHP的curl实现get,post和cookie(实例介绍)
- 详解php用curl调用接口方法,get和post两种方式
- php使用CURL模拟GET与POST向微信接口提交及获取数据的方法
- PHP如何使用cURL实现Get和Post请求
- PHP中使用CURL发送get/post请求上传图片批处理功能
- php curl发起get与post网络请求案例详解
- PHP curl get post 请求的封装函数示例【get、post、put、delete等请求类型】
相关文章
PHP获取搜索引擎关键字来源的函数(支持百度和谷歌等搜索引擎)
通过网站功能来增加一字段,获取来源关键字,如何获取来源关键字,代码发在下面,里面包含(百度、谷歌、雅虎、搜狗、搜搜、必应、有道)几大搜索引擎的获取方法,代码中均注明,希望对你有帮助,分享一下2012-10-10


最新评论