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:

<?php
/* this line uses to see the type of browser*/
$agent = $_SERVER['HTTP_USER_AGENT'];

/* this line uses to see script excute from where GET(URL) */
$uri = $_SERVER['REQUEST_URI'];

/* this line uses to see visitor's IP Address */
$ip = $_SERVER['REMOTE_ADDR'];

/* this line uses to see where the referer script come from */
$ref = $_SERVER['HTTP_REFERER'];

/* this line uses to see the visitor's proxy */
$real = $_SERVER['HTTP_X_FORWARDED_FOR'];

/* 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 */
fclose($fp);

?>

That's all.....

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

Related Posts by Categories



0 comments:

Post a Comment

Maybe this is what you looking for

 

Subscribe Now

Followers

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