Created
November 9, 2012 09:12
-
-
Save hidayat365/4044681 to your computer and use it in GitHub Desktop.
Helper Function untuk cURL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* cURL_Helper: Helper untuk cURL | |
* @param string $url URL yang mau kita buka | |
* @param optional string $spost data yang mau kita POST ke $url | |
* @timeout optional integer waktu sampai timeout | |
*/ | |
function cURL_Helper($url, $spost=FALSE, $timeout=FALSE) | |
{ | |
// inisialisasi curl | |
$ch = curl_init(); | |
curl_setopt($ch,CURLOPT_URL,$url); | |
curl_setopt($ch,CURLOPT_POST,$spost?1:0); | |
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); | |
if ($spost) curl_setopt($ch,CURLOPT_POSTFIELDS,$spost); | |
if ($timeout) curl_setopt($ch,CURLOPT_TIMEOUT,$timeout); | |
// periksa apakah ada error | |
if (curl_errno($ch)) { | |
$curlerr = curl_error($ch); | |
die; | |
} | |
// jalankan curl | |
$output = curl_exec($ch); | |
if($ch) curl_close($ch); | |
// return result | |
return $output; | |
} | |
// coba panggil graph PHP Indonesia pakai curlhelper | |
$url = 'http://graph.facebook.com/35688476100'; | |
$web = cURL_Helper($url); | |
// tampilkan hasilnya | |
print $web; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment