private function gapi::curlRequest in Google Analytics Statistics 7.x
Same name and namespace in other branches
- 7 includes/gapi.class.php \gapi::curlRequest()
HTTP request using PHP CURL functions Requires curl library installed and configured for PHP
Parameters
Array $get_variables:
Array $post_variables:
Array $headers:
1 call to gapi::curlRequest()
- gapi::httpRequest in inc/
gapi.class.php - Perform http request
File
- inc/
gapi.class.php, line 480
Class
- gapi
- GAPI - Google Analytics PHP Interface
Code
private function curlRequest($url, $get_variables = null, $post_variables = null, $headers = null) {
$ch = curl_init();
if (is_array($get_variables)) {
$get_variables = '?' . str_replace('&', '&', urldecode(http_build_query($get_variables)));
}
else {
$get_variables = null;
}
curl_setopt($ch, CURLOPT_URL, $url . $get_variables);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//CURL doesn't like google's cert
if (is_array($post_variables)) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_variables);
}
if (is_array($headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
$response = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return array(
'body' => $response,
'code' => $code,
);
}