index.php
Код:
<?php
require_once("lib.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Form</title>
</head>

<body>
<?
if($error == true){
****echo "".$err_mess."
";
****echo $form;
}

echo $text;

?>
</body>
</html>
далее lib.php
Код:
<?php
set_magic_quotes_runtime(0);
define(&#39;BEGIN_TRANSACTION&#39;, 1);
define(&#39;END_TRANSACTION&#39;, 2);
require_once("mysql.php");
$sql = new sql_db;
$host = "localhost";
$user = "root";
$pass = "";
$db = "test";
if(isset($_POST[&#39;Start&#39;])) $start=$_POST[&#39;Start&#39;];
if(isset($_POST[&#39;End&#39;])) $end=$_POST[&#39;End&#39;];

$pattern = "/^([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}).+([0-9]{2})\/([A-Za-z]{3})\/([0-9]{4}):([0-9]{2}):([0-9]{2}):([0-9]{2}).+\"POST.(\/.*)\s.*\"\s+([0-9]{1,3}).([0-9]*)/";
$pattern1 = "/([0-9]{4})\-([0-9]{2})-([0-9]{2})\s([0-9]{2}):([0-9]{2}):([0-9]{2})/";

$form = "

Время вводится в формате YYYY-MM-DD hh:mm:ss (YYYY - год, ММ - месяц, DD - день месяца, hh:mm:ss - час, минута и секунда)</p>
****<form action=\"".$PHP_SELF."\" method=\"post\">\n
****Дата от: <input type=\"text\" maxlength=\"19\" name=\"Start\" size=\"40\" *value=\"".$start."\">

****Дата до: <input type=\"text\" maxlength=\"19\" name=\"End\" size=\"40\" value=\"".$end."\">

****подстрока URL: <input type=\"text\" maxlength=\"255\" size=\"35\" name=\"Page\">

****<input type=\"submit\" value=\"Send\" name=\"Submit\">
****</form>";

if(isset($_POST[&#39;Submit&#39;]) && $_POST[&#39;Submit&#39;] ="Send"){
****$error = FALSE;
// *
****if (isset($_POST[&#39;Start&#39;]) && $_POST[&#39;Start&#39;] !="" && !preg_match($pattern1,$_POST[&#39;Start&#39;],$stmatch)){
 *$start = $_POST[&#39;Start&#39;];
 *$error = true;
 *$err_mess = "Неправильно заполнено поле \"Время от: \"!";
****}
****if (isset($_POST[&#39;End&#39;]) && $_POST[&#39;End&#39;] !="" && !preg_match($pattern1,$_POST[&#39;End&#39;],$enmatch)){
 *$end = $_POST[&#39;End&#39;];
 *$error = true;
 *$err_mess = "Неправильно заполнено поле \"Время до: \"!";
****}
****if($error == false){
 *$fp = fopen("access.log","r");
 *$i = 0;
 *while (!feof ($fp)) {
 * * *$buffer = fgets($fp);
 * *if(preg_match($pattern,$buffer,$matches)){
 * *if(!is_numeric($matches[3])){
 * *****$matches[3] = eregi_replace("Jan","1",$matches[3]);
 * *****$matches[3] = eregi_replace("Feb","2",$matches[3]);
 * *****$matches[3] = eregi_replace("Mar","3",$matches[3]);
 * *****$matches[3] = eregi_replace("Apr","4",$matches[3]);
 * *****$matches[3] = eregi_replace("May","5",$matches[3]);
 * *****$matches[3] = eregi_replace("Jun","6",$matches[3]);
 * *****$matches[3] = eregi_replace("Jul","7",$matches[3]);
 * *****$matches[3] = eregi_replace("Sep","9",$matches[3]);
 * *****$matches[3] = eregi_replace("Oct","10",$matches[3]);
 * *****$matches[3] = eregi_replace("Nov","11",$matches[3]);
 * *****$matches[3] = eregi_replace("Dec","12",$matches[3]);
 * *****$matches[3] = eregi_replace("Aug","8",$matches[3]);
 * *}
 * *$time = gmmktime($matches[5],$matches[6],$matches[7],$matches[3],$matches[2],$matches[4]);
 * *****if(preg_match("/^(\/.*)(\?.*)/",$matches[8],$mat)){
 * * *$link = $mat[1];
 * *****$get = $mat[2];
 * *****} else {
 * *****$link = $matches[8];
 * *****$get = "";
 * *}
 * *$req = $matches[9];
 * *$size = $matches[10];
 * *$params[] = $matches[1].",".$time.",".$link.",".$req.",".$size.",".$get;
 * *$i++;
 * *}
 *}
 *fclose ($fp);
****}
} *else {
****$text = $form;
}
****if($stmatch) {
 *$st_time = gmmktime($stmatch[4],$stmatch[5],$stmatch[6],$stmatch[2],$stmatch[3],$stmatch[1]);
****}
****if($enmatch) $en_time = gmmktime($enmatch[4],$enmatch[5],$enmatch[6],$enmatch[2],$enmatch[3],$enmatch[1]);
****if(isset($_POST[&#39;Page&#39;]) && $_POST[&#39;Page&#39;] !="") $url = "/".$_POST[&#39;Page&#39;];
****
****for($j=0;$j<$i;$j++){
 *list($ip,$time,$link,$req,$size,$get) = explode(",",$params[$j]);
 *if($req != 200) continue;
 *if(is_numeric($st_time) && ($time < $st_time)) continue;
 *if(is_numeric($en_time) && ($en_time < $time)) continue;
 *if($url && $url != $link) continue;
 *$sQuerry[] = $ip.",".$time.",".$link.",".$req.",".$size.",".$get;
****}
****

$res = $sql -> sql_db($host,$user,$pass,$db, "");

****if($res){
****
 *$trun1 = "TRUNCATE TABLE `ip`";
 *$trun2 = "TRUNCATE TABLE `url`";
 *$trun3 = "TRUNCATE TABLE `request`";
 *
 *$sql -> sql_query($trun1,1);
 *$sql -> sql_query($trun2,1);
 *$sql -> sql_query($trun3,1);
 *foreach($sQuerry as $val){
 *****list($ip,$time,$link,$req,$size,$get) = explode(",",$val);
 *****$sq1 = "INSERT INTO ip (`ip_id`, `address`) VALUES (&#39;&#39;, &#39;".$ip."&#39;)";
 *****$sq2 = "INSERT INTO url (`link_id`, `link`) VALUES (&#39;&#39;, &#39;".$link."&#39;)";
 *****$sq3 = "INSERT INTO request (`id`, `time`,`ip_id`, `link_id`, `get`, `size`) VALUES (&#39;&#39;, &#39;".$time."&#39;, &#39;".$ip."&#39;,&#39;".$link."&#39;,&#39;".$get."&#39;,&#39;".$size."&#39;)";
 *****$sql -> sql_query($sq1,2);
 *****$sql -> sql_query($sq2,2);
 *****$sql -> sql_query($sq3,2);
 *}
****}

?>
mysql.php не буду сюда вставлять так как он не очень то и нужен тут +/