PHP CURL模拟GET及POST函数代码
2014-10-25 03:47
405 查看
<?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;
}
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模拟GET及POST函数代码
- PHP CURL模拟GET及POST函数
- php中用socket模拟http中post或者get提交数据的示例代码
- PHP fsockopen介绍及fsockopen封装函数实现模拟GET或POST请求
- php curl模拟post请求和提交多维数组的示例代码
- php的curl函数模拟post、get数据提交,速度非常慢的处理办法
- php中用socket模拟http中post或者get提交数据的示例代码
- php curl 发送GET,POST请求的函数
- php curl实现get和post的代码
- PHP实用函数:stream_context_create()模拟POST/GET
- php curl模拟 get,post提交,上传文件,下载文件
- php 模拟POST|GET操作实现代码
- PHP curl get post 提交函数
- PHP实用函数手册:stream_context_create()模拟POST/GET
- C#代码模拟http发送get和post请求
- [PHP代码] 用php的fsocket模拟get提交 模拟post提交表单
- php的curl函数模拟post、get数据提交,速度非常慢的处理办法