WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
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 Index
Web Development Resources
Web Development Content
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
Mobile Dev World

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 3 times)
Viewed : 3723
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

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

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
Current Page's URL using PHP
Categories : PHP, Beginner Guides, Global Variables
Get the self URL of current page
Categories : PHP, URLs, Beginner Guides
Newbie Notes #1 - Making a form return to itself
Categories : PHP, Beginner Guides, HTML and PHP
Automatic global variable definer
Categories : PHP, Variables, Beginner Guides
Multiple Select box, Select multiple Items from Menu.List box
Categories : PHP, HTML and PHP, Beginner Guides
mySQL/PHP/search with multientry form and table output with colored rows
Categories : PHP, Beginner Guides, MySQL, HTML and PHP, Databases
A very simple PHP single password cookie based login without usernames.
Categories : PHP, Cookies, Security, Beginner Guides
Newbie Notes #3 - What went wrong? A useful little debugging aid
Categories : PHP, Beginner Guides, Debugging
email new items in db
Categories : PHP, Email, Databases, MySQL, Beginner Guides
Logwriter
Categories : PHP, Log Files
A beginner's session handling class
Categories : PHP, PHP Classes, Sessions, Beginner Guides
logger class (PHP5 +)
Categories : PHP, PHP Classes, Log Files, XML
Form Submission Using Array's
Categories : PHP, HTML and PHP, Beginner Guides, Arrays