-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrapper.php
More file actions
30 lines (28 loc) · 963 Bytes
/
Copy pathwrapper.php
File metadata and controls
30 lines (28 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
// http://php.net/manual/en/reserved.variables.httpresponseheader.php#117203
// Original solution modified to return the response code only and a 200 by default if nothing exists.
function getResponseCodeFromHeaders( $headers )
{
$head = array();
foreach( $headers as $k=>$v )
{
$t = explode( ':', $v, 2 );
if( isset( $t[1] ) )
$head[ trim($t[0]) ] = trim( $t[1] );
else
{
$head[] = $v;
if( preg_match( "#HTTP/[0-9\.]+\s+([0-9]+)#",$v, $out ) )
return intval($out[1]);
}
}
// If we couldn't find a code, something is wrong, return something scary-error level.
return 500;
}
header('Content-Type: application/json');
$url = $_POST['url'];
$riot_api_response = file_get_contents($url.'api_key=RGAPI-1cfc39dd-2438-10d3-fc88-20289729955c');
$result = json_decode($riot_api_response, true);
$result['response'] = getResponseCodeFromHeaders($http_response_header);
print_r(json_encode($result));
?>