File: httpbin.php

package info (click to toggle)
wapiti 3.2.10%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,156 kB
  • sloc: python: 30,204; xml: 2,707; php: 1,267; sql: 1,183; sh: 444; javascript: 230; ruby: 47; makefile: 39
file content (49 lines) | stat: -rw-r--r-- 1,111 bytes parent folder | download
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php

function get_url() {
    if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')   
         $url = "https://";   
    else  
         $url = "http://";   
    // Append the host(domain name, ip) to the URL.   
    $url.= $_SERVER["HTTP_HOST"];   
    
    // Append the requested resource location to the URL   
    $url.= $_SERVER["REQUEST_URI"];
    return $url;
}

$dump = array(
    "headers" => array(),
    "url" => get_url(),
    "args" => array(),
    "form" => array(),
    "files" => array()
);

if ($_SERVER["CONTENT_TYPE"] == "application/json") {
    $json = file_get_contents('php://input');
    $dump["data"] = $json;
    $dump["json"] = json_decode($json);
}

$headers = apache_request_headers();
foreach ($headers as $header => $value) {
    $dump["headers"][$header] = $value;
}

foreach ($_GET as $key => $value) {
    $dump["args"][$key] = $value;
}

foreach ($_POST as $key => $value) {
    $dump["form"][$key] = $value;
}

foreach ($_FILES as $key => $value) {
    $dump["files"][$key] = file_get_contents($value["tmp_name"]);
}

echo json_encode($dump, JSON_PRETTY_PRINT);

?>