Apr 14, 2008

[Tutorial] How to Creating .LOG system with FLAT FILE

If we have a website, of coursewe must know who comes to our website, and we must know who defacing our website (if has some people which is want defacing our website) . This tutorial perhaps will be helping all of website administrator to protecting their website

One website has .log system, one of them:
beside for know who is visitors, log file is very helpful to security analysis, I will giving some log file using script PHP system:

Script System LOG with FLAT FILE:
Quote:

/* this is for seeing browser type
$agent = $_SERVER['HTTP_USER_AGENT'];

/* this is for looking script at execution from where GET(URL)
$uri = $_SERVER['REQUEST_URI'];

/* this is for looking IP visitor
$ip = $_SERVER['REMOTE_ADDR'];

/* This is for looking script at refer from some place
$ref = $_SERVER['HTTP_REFERER'];

/* This is for looking Proxy from visitor
$asli = $_SERVER['HTTP_X_FORWARDED_FOR'];

/* This is for looking visitor connection
$via = $_SERVER['HTTP_VIA'];

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

/* ATTENTION: If visitor using Proxy transparent
/* So $_SERVER['HTTP_X_FORWARDED_FOR'] will be showing real IP from visitors
/* But $_SERVER['REMOTE_ADDR'] only showing Proxy and not real IP visitor

/* This is for description variabel entry_line:
$entry_line = "Time: $dtime | Real IP: $ip | Browser: $agent | URL: $uri | Referrer: $ref | Proxy: $asli | Connection: $via
";
/* <-- ATTENTION!! It must be new line or enter once again to be new line

/* "fopen()" This funcion to open file, "a" it is more important.
/* This function will be active if file "jejak.txt" doesn't has in server so PHP will be creating
$fp = fopen("jejak.txt", "a");

/* "fputs()" This function to writing log in file
fputs($fp, $entry_line);

/* "fclose()" This function to closing file
fclose($fp);

?>

The function from php System LOG with FLAT FILE , This is more useful for me more than using MySql.

No comments: