<?
/*
CREATE TABLE `tb_access_log` (
  `ind` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `ip` varchar(15) DEFAULT NULL,
  `user` varchar(20) DEFAULT NULL,
  `method` varchar(5) DEFAULT NULL,
  `path` varchar(150) DEFAULT NULL,
  `status` varchar(10) DEFAULT NULL,
  `bytes` int(11) DEFAULT '0',
  `referer` varchar(150) DEFAULT NULL,
  `agent` varchar(150) DEFAULT NULL,
  `wtime` varchar(10) DEFAULT NULL,
  `wdate` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`ind`)
) ENGINE=MyISAM;
*/

//
function getline( $fp )
{
	$result = "";
	while( !feof( $fp ) )
	{
		$tmp = fgetc( $fp );
		if( ord($tmp) == 10 )
		{
			return $result;
		}
		$result .= $tmp;
	}
	return $result;
}

function getmktime($date, $time)
{
	$m['Jan'] = '01';
	$m['Feb'] = '02';
	$m['Mar'] = '03';
	$m['Apr'] = '04';
	$m['May'] = '05';
	$m['Jun'] = '06';
	$m['Jul'] = '07';
	$m['Aug'] = '08';
	$m['Sep'] = '09';
	$m['Oct'] = '10';
	$m['Nov'] = '11';
	$m['Dec'] = '12';

	$arr_date = explode("/", $date);
	$arr_date[1] = $m[$arr_date[1]];
	$hour_parts = explode(" ", $time);
	
	return strtotime($arr_date[2]."-".$arr_date[1]."-".$arr_date[0]." ".$time);
}

// ¾ÆÆÄÄ¡ ·Î±×ÆÄÀÏ
$fp = fopen("../access_log", 'r'); // filepds.com-access_log
if($fp)
{
	while( !feof($fp) )
	{
		$line = getline($fp);
		$line = rtrim($line, "\n");

		preg_match("/^(\S+) (\S+) (\S+) \[([^:]+):(\d+:\d+:\d+) ([^\]]+)\] \"(\S+) (.*?) (\S+)\" (\S+) (\S+) (\".*?\") (\".*?\")$/", $line, $matches);
		if (isset($matches[0]))
		{
			$ip = $matches[1];
			$identity = $matches[2];
			$user = $matches[2];
			$date = $matches[4];
			$time = $matches[5];
			$timezone = $matches[6];
			$method = $matches[7];
			$path = $matches[8];
			$protocol = $matches[9];
			$status = $matches[10];
			$bytes = $matches[11];
			$referer = $matches[12];
			$agent = $matches[13];

			// added
			$wtime = getmktime($date, $time);
			$wdate = date("Y-m-d", $wtime);

			// Do Something
			$query = "insert into tb_access_log( ip, user, method, path, status, bytes, referer, agent, wtime, wdate) values( '$ip', '$user', '$method', '$path', '$status', '$bytes', '$referer', '$agent', '$wtime', '$wdate')";
			//mysql_query($query,$dbcon);
			echo $query;
			echo "<p>";

		}
	}
	fclose($fp);
}
?>