getPage และ postPage ด้วย php+cURL

 - by NAzT

มีฟังก์ชั่น 2 อัน ชื่อตรงตัวเลยครับว่าให้ทำอะไร วิธีใช้ก็อ่านเอาที่ Prototype ของ function ได้เลยครับ

//-----------------------------------------------------------------------------------
function ($url, $referer, $timeout, $header){
if(!isset($timeout))
$timeout=30;
$ = _init();
if(strstr($referer,"://")){
_setopt ($, CURLOPT_REFERER, $referer);
}
_setopt ($, CURLOPT_URL, $url);
_setopt ($, CURLOPT_TIMEOUT, $timeout);
_setopt ($, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5)));
_setopt ($, CURLOPT_HEADER, (int)$header);
_setopt ($, CURLOPT_RETURNTRANSFER, 1);
_setopt ($, CURLOPT_SSL_VERIFYPEER, 0);
$html = _exec ($);
_close ($);
return $html;
}
//-----------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------
function postPage($url,$pvars,$referer,$timeout){
if(!isset($timeout))
$timeout=30;
$ = _init();
$post = http_build_query($pvars);
if(isset($referer)){
_setopt ($, CURLOPT_REFERER, $referer);
}
_setopt ($, CURLOPT_URL, $url);
_setopt ($, CURLOPT_TIMEOUT, $timeout);
_setopt ($, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5)));
_setopt ($, CURLOPT_HEADER, 0);
_setopt ($, CURLOPT_RETURNTRANSFER, 1);
_setopt ($, CURLOPT_SSL_VERIFYPEER, 0);
_setopt ($, CURLOPT_POST, 1);
_setopt ($, CURLOPT_POSTFIELDS, $post);
_setopt ($, CURLOPT_HTTPHEADER,
("Content-type: application/x-www-form-urlencoded"));
$html = curl_exec ($curl);
curl_close ($curl);
return $html;
}
//-----------------------------------------------------------------------------------
จาก  http://www.tellinya.com  คร้าบ

Related Blogs

เรื่องที่เกี่ยวข้อง