WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : PHP Event Logger
Categories : PHP, Log Files, Errors and Logging, Beginner Guides Click here to Update Your Picture
Ethan Sterling
Date : Oct 06th 2008
Grade : 2 of 5 (graded 4 times)
Viewed : 10302
File : 4873.php
Images : No Images for this code example.
Search : More code by Ethan Sterling
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
Like this code?
Show the author your appreciation.
 

A simple event logger written in PHP.

The event logger (event_logger.php)

<?PHP
/*
PHP Event Logger By Ethan Sterling

Usage: 'bool' log_event('string' $file, 'string' $info, 'string', $script)
Purpose: Resize an image

Parameters:-

file: Which file should the event be logged to

info: Any information that you wish to be stored in the log
      Such as information about any error that may have occoured

script: Which script triggered the log event, defaults to the contents
        of $_SERVER['PHP_SELF']. If the log event is being called from
        within a file that has been included, set this value to __FILE__
        else use $_SERVER['PHP_SELF'] or ignore this parameter

Returned values:-

Returns TRUE on success

Example:-

log_event("log.txt", $_SERVER['HTTP_USER_AGENT']);

This example will log the clients user-agent, as sent by the browser, to the
file 'log.txt', and will use the default value for $script ($_SERVER['PHP_SELF'])
*/

function log_event($file, $info, $script = "")
    {
   
   
//Get the IP of the computer that triggered the log event
   
$ip = $_SERVER['REMOTE_ADDR'];

   
//Get the time that the log event was triggered
   
$time = time();
   
   
//Work out what script called the log event
    //This is needed because variables cannot be used as default values in a function
   
if($script == "")
        {
       
$script = $_SERVER['PHP_SELF'];
        }
       
   
//Build the log string containing logged IP, time, script and event information
   
$string = "$ip - $time - $script - $info\r\n";

   
//Open the log file for writing (or create and open it if it does not exist)
   
if(!$f = fopen($file, "a")) return FALSE;

   
//Write to the log file
   
if(!fwrite($f, $string)) return FALSE;

   
//Close the logfile
   
fclose($f);

   
//Return a value of TRUE to indicate that the function has finished successfully
   
return TRUE;
    }

?>


The example script, that calls the logger

<?PHP
//Include the event logger script
include('event_logger.php');

//Log the users user agent (as reported bu the browser) to the file log.txt
log_event("log.txt", $_SERVER['HTTP_USER_AGENT']);

?>



Making a simple Hit-Log using PHP and MySql
Categories : PHP, Log Files, Beginner Guides, Databases, MySQL
DB Connection Function with error handling and email failure notices
Categories : PHP, MySQL, Errors and Logging, Databases, Errors and Logging
Newbie Notes #8 - A cron trick
Categories : PHP, CURL, Beginner Guides
Simple Cookie example
Categories : PHP, Beginner Guides, Cookies
How to update selected fields only
Categories : PHP, Databases, Beginner Guides
Creating a Language File
Categories : PHP, Beginner Guides, Filesystem
Upload Via FTP - an alternative to move_uploaded_file
Categories : PHP, FTP, Beginner Guides
Ping a Server and run a command to fix it if it is down
Categories : PHP, Errors and Logging, Regexps
A simple function to prevent undefined $_POST/$_GET/$_SESSION variable errors
Categories : PHP, Variables, Errors and Logging
Current Page's URL using PHP
Categories : PHP, Beginner Guides, Global Variables
PHP Class to calculate Degrees Minutes Seconds to Decimal Degrees
Categories : PHP, PHP Classes, Geo Related, Beginner Guides
Intelligent 404 Handler
Categories : PHP, Errors and Logging
How to display any array in several rows and columns of a table. Not just in one column or in alternate rows. This example shows a nice color table generated with PHP, but can be used with any array values(e.g. Database)
Categories : Arrays, PHP, Miscellaneous, Beginner Guides, Graphics
Simple Session example
Categories : PHP, Beginner Guides, Sessions
PHP Based Apache + Mysql Error Log Parser
Categories : PHP, PHP Classes, Apache, MySQL, Log Files