Var Dump HTTP POST到fwrite文件

时间:2019-01-21 13:04:53

标签: php arrays

我试图将json中所有HTTP POST都转储到一个文本文件中,调用logs.txt,可以对该文件进行写操作,并且

<?php
$myfile = fopen("/var/www/html2/inc/logs/logs.txt", "a") or die("Unable to open file!");
$data = json_decode($_POST, true);

fwrite($myfile, "\n".$data);
fclose($myfile);
?>

结果实际上是空的。我确实尝试过该文件是否可写,是的,它创建了该文件,没有文件夹权限问题,我想使用序列化,但是它不起作用。

1 个答案:

答案 0 :(得分:1)

ports: - "<interface_ip>:<host_port>:<container_port>" 可能是错误。

要将数组转换为JSON,您需要使用:

json_decode() expects parameter 1 to be string, array given

http://php.net/manual/de/function.json-encode.php

相关问题