PHP Web Logging

From JasonAntmanWiki
Jump to: navigation, search


I've implemented a small PHP- and MySQL-based logging scheme for logging access to Apache Auth protected PHP scripts.

Contents

logging.php

Just a simple way to log information on page accesses from PHP to MySQL

API

To use, simply add an import statement and a call to the function at the top of your PHP script. As example:

The function, if it succeeds, should return true.

Database Setup

To initialize a table in the database for logging:

CREATE TABLE `log_external` (
  `pKey` int(11) NOT NULL auto_increment,
  `timestamp` int(11) default NULL,
  `auth_user` tinytext,
  `auth_type` tinytext,
  `URL` tinytext,
  `local_filename` tinytext,
  `remoteIP` tinytext,
  `client` tinytext,
  `additional` text,
  PRIMARY KEY  (`pKey`)
);


This table format also includes a full TEXT field called "additional" to allow adding of additional information (errors, new fields, etc.) while retaining the table format. The suggested format of this field is a set of text lines, of the format "FIELD=value", separated by /r/n (CR-LF pairs). Values are whitespace-ignorant.

Function

Views
Notice - this is a static HTML mirror of a previous MediaWiki installation. Pages are for historical reference only, and are greatly outdated (circa 2009).