4 มกราคม 2009getPage และ postPage ด้วย php+cURL

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

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


Related Blogs


Tags: , , , , ,
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply

Comment ไม่ได้กดที่นี่

Get Adobe Flash playerPlugin by wpburn.com wordpress themes