소스 파일명 : stat_utils.php
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
echo "<script type='text/javascript'>
			$( function() {
				$(document).on('click', '.onedrive',
					function() {
						window.location.href ='./".basename($_SERVER['SCRIPT_FILENAME'])."?parm=onedrive' ;
					});
			});
		</script>";

function html_access ($script_filename,$dbi) {

	if ($_SERVER['REMOTE_ADDR'] == '192.168.0.1' or isset($_COOKIE['login_name'])) return;

// echo "<pre>";var_dump($dbi);echo "</pre>";

	$result = mysqli_query($dbi,"select * from dict.ip_count where ip='".$_SERVER['REMOTE_ADDR']."' ");
		if (mysqli_errno($dbi)) {echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";}
	if( mysqli_num_rows($result) == 0 ) return;

	$result_chk = mysqli_query($dbi,"select * from dict.stat_page where page_name='$script_filename' and stat_date=date_format(now(),'%Y-%m-%d') and last_ip='".$_SERVER['REMOTE_ADDR']."' "); // 
		if (mysqli_errno($dbi)) {echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";}
	$row_chk = mysqli_fetch_assoc($result_chk);

	if ( mysqli_num_rows($result_chk) == 0 and is_not_robot() ) {  //  
		mysqli_query($dbi,"insert into dict.stat_page (page_name,stat_date,last_ip,last_access,access_num,user_agent) values ('$script_filename', now(), '".$_SERVER['REMOTE_ADDR']."', now(), 1, '".$_SERVER['HTTP_USER_AGENT']."' )"); 
			if (mysqli_errno($dbi)) {echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";}		
	}

	if ( mysqli_num_rows($result_chk) > 0 and is_not_robot() ) {  //  
		$query = "update dict.stat_page set access_num=access_num+1, last_access=now() where page_name='$script_filename' and stat_date = '".date("Y-m-d")."' and last_ip='".$_SERVER['REMOTE_ADDR']."' ";
		mysqli_query($dbi,$query); 
			if (mysqli_errno($dbi)) {echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";}
	}

}

function is_not_robot() {

	$robot_arr = array('Googlebot','Bot','cowbot','empas','Yahoo! Slurp','WISEbot','BizBot04','CaliforniaBrownSpider','msnbot','1Noonbot','bingbot','Daumoa','Yeti/','MJ12bot','Google Web Preview','HTTrack','crawler','http_load 29jun2005','TurnitinBot','FunWebProducts','SiteBot/','QrobotW','ezooms.bot@','Microsoft URL Control','KISA','discobot','robot','pirst','spider/','lycosa.','checkprivacy','Crawler','Preview','bsalsa.com','nutch agent','NAVER','360Spider','.org_bot','WebCapture ','instapaper','Ezooms',' DigExt','siteexplorer','Nutch','flipboard','wotbox','Navigator','linkAnalyze','Korea Internet & Security Agency','_bot');
	foreach($robot_arr as $key => $value) {
		if(strpos($_SERVER['HTTP_USER_AGENT'], $value)!==false) {
			return false; // this is robot
		}
	}
	return true;
}

?>