PHP CURL模擬GET及POST函數(shù)代碼
更新時間:2010年04月25日 15:15:45 作者:
PHP CURL模擬GET及POST函數(shù)代碼,需要的朋友可以參考下。
復制代碼 代碼如下:
<?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實現(xiàn)Get和Post請求的方法
- php中使用Curl、socket、file_get_contents三種方法POST提交數(shù)據
- php的curl實現(xiàn)get和post的代碼
- PHP中的使用curl發(fā)送請求(GET請求和POST請求)
- PHP的curl實現(xiàn)get,post和cookie(實例介紹)
- 詳解php用curl調用接口方法,get和post兩種方式
- php使用CURL模擬GET與POST向微信接口提交及獲取數(shù)據的方法
- PHP如何使用cURL實現(xiàn)Get和Post請求
- PHP中使用CURL發(fā)送get/post請求上傳圖片批處理功能
- php curl發(fā)起get與post網絡請求案例詳解
- PHP curl get post 請求的封裝函數(shù)示例【get、post、put、delete等請求類型】
相關文章
使用ThinkPHP自帶的Http類下載遠程圖片到本地的實現(xiàn)代碼
Thinkphp是國人開發(fā)一個PHP框架,該框架相比國外的一些框架也毫不遜色。強大的ORM,插件,分組等功能讓人愛不釋手。2011-08-08用mysql觸發(fā)器自動更新memcache的實現(xiàn)代碼
不錯的一篇文章,用于項目中可以帶來更多的便利,按照方法已經調試成功,可以大大提高項目的速度。2009-10-10在VSCode中配置PHP開發(fā)環(huán)境的實戰(zhàn)步驟
最近要寫一些可視化的網站,所以先把需要的環(huán)境配好吧,下面這篇文章主要給大家介紹了關于在VSCode中配置PHP開發(fā)環(huán)境的相關資料,文中通過圖文介紹的非常詳細,需要的朋友可以參考下2022-11-11