Thursday, December 10, 2009

Create LOG System with FLAT File

Create LOG System with FLAT File
 If we have a website, of course we would want out traces of our website visitors. In this PHP Tutorial, i will show you how to make simple LOG System with FLAT File.

Some uses of the system log include:
other than to find out visitor information, log files, too useful to assist the analysis of security

Script LOG System with FLAT FILE:

/* this line uses to see the type of browser*/

/* this line uses to see script excute from where GET(URL) */

/* this line uses to see visitor's IP Address */

/* this line uses to see where the referer script come from */

/* this line uses to see the visitor's proxy */

/* this line uses to see visitor's connection */
$via = $_SERVER['HTTP_VIA'];

/* this is date variable */
$dtime = date('r');

/* attention, when visitors use a transparent proxy, then the $ _SERVER [ 'HTTP_X_FORWARDED_FOR'] will display the real visitor's IP, otherwise $ _SERVER [ 'REMOTE_ADDR'] will show visitor's Proxy. Untuk lebih jelasnya tentang macam-macam Proxy, saya akan menjelaskannya di tutorial yang lain */

/* This is description of entry_line variable */
$entry_line = "Time: $dtime | Real IP: $ip | Browser: $agent  | URL: $uri | Referrer: $ref | Proxy: $real | Connection: $via
   /* <-- attention!! This should be a new line so that the result becomes a new line */

/* "fopen()" function to open file, this is the most important!!, this is used if "tracking.txt" can not be found on the server, then PHP will create */
$fp = fopen("tracking.txt", "a");

/* "fputs()" the function is to write log into file */
fputs($fp, $entry_line);

/* "fclose()" the function is to close the file */


That's all.....

I think this Php FLAT FILE LOG function System pretty useful than using MySql connection

Related Posts by Categories


Post a Comment

Maybe this is what you looking for


Subscribe Now


IT Skill is not enough... Copyright © 2009 Designed by Bie Blogger Template