2011-05-07 47 views
0

我异步地发布到一个PHP文件,它回应了几个关键的东西。我想将它的所有输出写入日志文件。最简单的方法是什么?将回声传送到输出文件

+0

你从哪里发布? – 2011-05-07 20:37:25

+0

我正在从网页发布表单数据,表单将发布到外部PHP文件,并且不会显示/转到该表单。 – AKor 2011-05-07 20:40:11

回答

0
<?php 
// Before you have any output! 
ob_start(); 

// All of your other code, echos, etc. 

// Sends the Output Buffer, also captures it in the $output variables 
$output = ob_get_flush(); 

// Some extra info for the Logfile, so you know when and who saw it 
$logPrefix = "\n\n". 
      "Time: ".date('Y-m-d H:i:s')."\n". 
      "IP: ".$_SERVER['REMOTE_ADDR']."\n\n"; 

// Write the data to the Logfile, and append it to the end (if file already exists) 
file_put_contents('yourLogfile.txt' , $logPrefix.$output , FILE_APPEND); 
?>