Created
June 15, 2012 18:29
-
-
Save cccaldas/2938040 to your computer and use it in GitHub Desktop.
request_helper
This file contains 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 | |
function request_get($url) { | |
return file_get_contents($url); | |
} | |
function request_post($url, $data=null){ | |
$handler = curl_init($url); | |
curl_setopt($handler, CURLOPT_RETURNTRANSFER, 1); | |
if(isset($data)){ | |
$params = ""; | |
foreach($data as $key => $value){ | |
$params .= urlencode($key).'='.urlencode($value).'&'; | |
} | |
curl_setopt($handler, CURLOPT_POSTFIELDS, $params); | |
curl_setopt($handler, CURLOPT_POST, 1); | |
} | |
$result = curl_exec($handler); | |
curl_close($handler); | |
return $result; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment