Revision: 65550
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at December 18, 2013 12:18 by dmertl
Initial Code
<?php
class Logger {
protected $fh;
public function __construct() {
$this->fh = fopen('log.txt', 'a+');
}
public function log($msg) {
if(!$this->fh) {
throw new Exception('Unable to open log file for writing');
}
if(fwrite($this->fh, $msg . "\n") === false) {
throw new Exception('Unable to write to log file.');
}
}
public function __destruct() {
fclose($this->fh);
}
}
$logger = new Logger();
$logger->log(date('m-d-Y H:i:s') . ' ' . $_SERVER['REMOTE_ADDR']);
$logger->log('$_POST: ' . print_r($_POST, true));
$logger->log('$_GET: ' . print_r($_GET, true));
$logger->log('$_FILES: ' . print_r($_FILES, true));
Initial URL
Initial Description
Write request data to a log file
Initial Title
PHP - Log request data
Initial Tags
http, php
Initial Language
PHP