Php将文章标题保存到文件中,以便以后查看


Php save post headers to file to view later

我正在尝试查看所有的页头并将它们保存到文件中

file_put_contents("/var/www/rnli.hutber.com/controllers/api/location/post.json", json_encode($_POST));

然而,它只输出以下内容:

[]

但使用另一个服务,我知道有一个完整的后

Time: Tue, 07 Apr 15 09:36:37 -0700
Source ip: 77.103.1.179
Headers (Some may be inserted by server)
REQUEST_URI = /post.php
QUERY_STRING = 
REQUEST_METHOD = POST
GATEWAY_INTERFACE = CGI/1.1
REMOTE_PORT = 34686
REMOTE_ADDR = 77.103.1.179
HTTP_USER_AGENT = Apache-HttpClient/UNAVAILABLE (java 1.4)
HTTP_CONNECTION = close
HTTP_HOST = posttestserver.com
CONTENT_LENGTH = 201
CONTENT_TYPE = application/json
HTTP_ACCEPT = application/json
UNIQUE_ID = VSQHldBx6hIAABF0UacAAAAF
REQUEST_TIME_FLOAT = 1428424597.7112
REQUEST_TIME = 1428424597
No Post Params.
== Begin post body ==
{"auth_token":"hutber","test":"ing","location":{"latitude":"51.61755157","longitude":"-0.13905254","accuracy":"29.0","speed":"0.0","bearing":"0.0","altitude":"115.0","recorded_at":"2015-04-07T16:36Z"}}
== End post body ==
Upload contains PUT data:
{"auth_token":"hutber","test":"ing","location":{"latitude":"51.61755157","longitude":"-0.13905254","accuracy":"29.0","speed":"0.0","bearing":"0.0","altitude":"115.0","recorded_at":"2015-04-07T16:36Z"}}

http://posttestserver.com/data/2015/04/07/09.36.371974424473

尝试以下代码:

$data = array_merge(apache_request_headers(), $_POST, $_SERVER);
file_put_contents("/var/www/rnli.hutber.com/controllers/api/location/post.json", json_encode($data));

或者尝试这个代码

$headers = array();
foreach($_SERVER as $key => $value) {
    if (substr($key, 0, 5) <> 'HTTP_') {
        continue;
    }
    $headers[$key] = ($value);
}
file_put_contents("/var/www/rnli.hutber.com/controllers/api/location/post.json", json_encode($headers));