2011-05-07 99 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); 
?>