private function gapiRequest::fopenRequest in Google Analytics Statistics 7.2
HTTP request using native PHP fopen function Requires PHP openSSL
Parameters
Array $get_variables:
Array $post_variables:
Array $headers:
1 call to gapiRequest::fopenRequest()
- gapiRequest::request in includes/
gapi.class.php - Perform http request
File
- includes/
gapi.class.php, line 791
Class
- gapiRequest
- Google Analytics API request
Code
private function fopenRequest($get_variables = null, $post_variables = null, $headers = null) {
$http_options = array(
'method' => 'GET',
'timeout' => 3,
);
if (is_array($headers)) {
$headers = implode("\r\n", $headers) . "\r\n";
}
else {
$headers = '';
}
if (is_array($get_variables)) {
$get_variables = '?' . str_replace('&', '&', urldecode(http_build_query($get_variables, '', '&')));
}
else {
$get_variables = null;
}
if (is_array($post_variables)) {
$post_variables = str_replace('&', '&', urldecode(http_build_query($post_variables, '', '&')));
$http_options['method'] = 'POST';
$headers = "Content-type: application/x-www-form-urlencoded\r\n" . "Content-Length: " . strlen($post_variables) . "\r\n" . $headers;
$http_options['header'] = $headers;
$http_options['content'] = $post_variables;
}
else {
$post_variables = '';
$http_options['header'] = $headers;
}
$context = stream_context_create(array(
'http' => $http_options,
));
$response = @file_get_contents($this->url . $get_variables, null, $context);
return array(
'body' => $response !== false ? $response : 'Request failed, fopen provides no further information',
'code' => $response !== false ? '200' : '400',
);
}