欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PHP CURL模拟GET及POST函数代码

程序员文章站 2022-04-08 23:36:46
复制代码 代码如下:
复制代码 代码如下:

<?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;
}
?>