private function gapi::fopenRequest in Google Analytics Statistics 7
Same name and namespace in other branches
- 7.x inc/gapi.class.php \gapi::fopenRequest()
HTTP request using native PHP fopen function Requires PHP openSSL
Parameters
Array $get_variables:
Array $post_variables:
Array $headers:
1 call to gapi::fopenRequest()
- gapi::httpRequest in includes/
gapi.class.php - Perform http request
File
- includes/
gapi.class.php, line 537
Class
- gapi
- GAPI - Google Analytics PHP Interface
Code
private function fopenRequest($url, $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($url . $get_variables, null, $context);
return array(
'body' => $response !== false ? $response : 'Request failed, fopen provides no further information',
'code' => $response !== false ? '200' : '400',
);
}