Php将帖子标题保存到文件以便稍后查看

时间:2015-04-07 16:44:10

标签: php header

我正在尝试查看所有页面标题并将其保存到文件

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

2 个答案:

答案 0 :(得分:0)

请尝试以下代码:

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

答案 1 :(得分:0)

或尝试此代码

$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));