無E $w3a_option["unwrite"] = 10; //【前毘溷化対策】 // 前変換 1 => すE, 0 => しない $w3a_option["log_save"] = 1; //【前取得精度の向上対策】 // ホスト名の取得 1 => すE, 0 => しない $w3a_option["ip_ch"] = 1; /*==========================================================*/ /* 設定ここまで */ /*==========================================================*/ /*======================================*/ /* function */ /*======================================*/ //デバッグ /* function debug($data){ print ""; print_r($data); print ""; exit; } */ //データ生成 function mk_data_w3a($str){ $str = str_replace("\t","",$str); $str = "\t".$str; return $str; } //拒否E好汎匹濆み function exclude_read($uri){ if(file_exists($uri)){ if($arr_exclude = file($uri)){ $arr_exclude = array_unique($arr_exclude); return $arr_exclude; } } } //前変換 function log_save_enc($slist,$sval,$sw_break=0){ if(!$sval) return ; foreach ($slist as $k => $v) { if(strstr($sval,$v)){ $sval = str_replace ($v, '!'.$k.'!', $sval); if(!$sw_break) break; } } return $sval; } //配列に指E佑あEチェック function inc_array($str,$arr){ $retval = FALSE; if(is_array($arr)){ foreach($arr as $v){ if(stristr(trim($str), trim($v))){ $retval = TRUE; break; } } } return $retval; } //タイトE萋 function get_title($send_title="",$ref_path=""){ if($send_title){ $send_title = trim($send_title); if(function_exists('mb_convert_encoding')){ $send_title = mb_convert_encoding($send_title, "EUC", "SJIS"); } return $send_title; } //無E if(!$ref_path || !ini_get('allow_url_fopen')) return ""; $url = "http://".$_SERVER["HTTP_HOST"].$ref_path; if($_SERVER["QUERY_STRING"]){ $url .= "?".$_SERVER["QUERY_STRING"]."&W3A"; }else{ $url .= "?W3A"; } if($site = @file($url)){ foreach($site as $v){ $v = trim($v); if(!$v) continue; $file .= $v; if(preg_match("/]*>([^<]*)<\/title>/i",$file,$t)){ $title = trim($t[1]); if(function_exists('mb_convert_encoding')){ $title = mb_convert_encoding($title, "EUC", "SJIS"); } return $title; } } } } /*======================================*/ /* w3AnalyzerディEトE僖梗萋 */ /*======================================*/ if(!isset($_GET["W3A"]) || isset($w3a_send_title)){ //パス取得 if(isset($_GET["ref"])){ $sn = ""; $acc_path = ""; }else{ if($w3a_option["get_path_type"]){ $sn = substr( $_SERVER["REQUEST_URI"], 1, strlen($_SERVER["REQUEST_URI"]) - strlen(strrchr($_SERVER["REQUEST_URI"], "/"))); $sn = ereg_replace("[^/|~]","",$sn); if(substr($sn, 0, 2) == '~/') $sn = substr($sn, 2); $sn = str_replace("/", "../", $sn); }else{ $sn = $_SERVER['PHP_SELF']; if(strstr($sn,'~')) $sn = ereg_replace("/~[^/~/]+/","",$sn); $sn = eregi_replace("^(/|\./)", "", $sn); $sn = str_replace("/", "../", eregi_replace("[^/]", "", $sn)); } //w3AnalyzerディEトE僖絞埆 $acc_path = eregi_replace("^(/|\.\.?/)", "", $acc_path); $acc_path = $sn.eregi_replace("(/)$", "", $acc_path)."/"; } unset($sn); // if(@include_once($acc_path."inc/config.php")){ //時差指E気ったらとりあえずE椹間 if(!isset($time_diff)) $time_diff = 9; /*======================================*/ /* 設定の読み込みE */ /*======================================*/ if($log_type){ $w3a_logfile = $acc_path.$logdir.$logpref.gmdate("Ymd", time()+$time_diff*3600).$logext; }else{ $w3a_logfdir = $acc_path.$logdir.gmdate("Ym", time()+$time_diff*3600); if(!is_dir($w3a_logfdir)) mkdir($w3a_logfdir); $w3a_logfile = $w3a_logfdir."/".$logpref.gmdate("d", time()+$time_diff*3600).$logext; } /*======================================*/ /* 拒否E好箸瞭匹濆み */ /*======================================*/ unset($exclude); $exclude_fn = $acc_path.$datadir."exclude_hosts.txt"; if(file_exists($exclude_fn)) $exclude["hosts"] = exclude_read($exclude_fn); $exclude_fn = $acc_path.$datadir."exclude_urls.txt"; if(file_exists($exclude_fn)) $exclude["urls"] = exclude_read($exclude_fn); $exclude_fn = $acc_path.$datadir."exclude_uas.txt"; if(file_exists($exclude_fn)) $exclude["uas"] = exclude_read($exclude_fn); unset($exclude_fn); /*======================================*/ /* メイン処理 */ /*======================================*/ //バッファ初E $w3a_buf = array(); //HOSTの設E $w3a_buf["host"] = ($w3a_option["ip_ch"] ? gethostbyaddr($_SERVER["REMOTE_ADDR"]) : $_SERVER["REMOTE_ADDR"]); $write_flg = true; //E綾萢 if(inc_array($w3a_buf["host"],$exclude["hosts"])) $write_flg = false; if(inc_array($_SERVER["REMOTE_ADDR"],$exclude["hosts"])) $write_flg = false; if(inc_array($_SERVER["HTTP_REFERER"],$exclude["urls"])) $write_flg = false; if(inc_array($_SERVER["HTTP_USER_AGENT"],$exclude["uas"])) $write_flg = false; //パスとE侫.蕁爾寮瀋E if(isset($_GET["ref"])){ $w3a_buf["path"] = $_SERVER["HTTP_REFERER"]; $w3a_buf["path"] = ereg_replace("(https?|ftp|news)(://[[:alnum:]\+\$\;\?\.%,!#~*:@&=_-]+)(/.*)","\\3",$w3a_buf["path"]); //E侫.蕁縞埆 $w3a_buf["ref"] = $_GET["ref"]; if(count($_GET) > 1){ foreach($_GET as $k => $v){ if($k == "ref" || $k == "W3A") continue; $w3a_buf["ref"] .= '&'.$k; if($v != "") $w3a_buf["ref"] .= '='.urlencode($v); } } //パス編集 $w3a_buf["path"] = str_replace('?ref','',$w3a_buf["path"]); }else{ $w3a_buf["path"] = $_SERVER["SCRIPT_NAME"]; $w3a_buf["ref"] = $_SERVER["HTTP_REFERER"]; //クエE if($_SERVER["QUERY_STRING"]) $w3a_buf["path"] .= "?".$_SERVER["QUERY_STRING"]; } //ユーザーエージェントの設E $w3a_buf["ua"] = $_SERVER["HTTP_USER_AGENT"]; //title $w3a_buf["title"] = get_title($w3a_send_title,$w3a_buf["path"]); //ID if($_COOKIE["w3a"]["id"]){ $w3a_buf["id"] = $_COOKIE["w3a"]["id"]; }else{ foreach(explode(".",$_SERVER["REMOTE_ADDR"]) as $v){ $w3a_buf["id"] .= dechex($v); } } @setcookie("w3a[id]",$w3a_buf["id"],time()+60*60*24*30,'/'); //vc (24時間以内はカウントアップしない) if(isset($_COOKIE["w3a"]["date"])){ if($_COOKIE["w3a"]["date"] > time()+60*60*24){ $w3a_buf["vc"] = ($_COOKIE["w3a"]["vc"] ? ++$_COOKIE["w3a"]["vc"] : 1); @setcookie("w3a[vc]",$w3a_buf["vc"],time()+60*60*24*30,'/'); @setcookie("w3a[date]",time(),time()+60*60*24*30,'/'); }else{ $w3a_buf["vc"] = ($_COOKIE["w3a"]["vc"] ? $_COOKIE["w3a"]["vc"] : 1); } }else{ $w3a_buf["vc"] = ($_COOKIE["w3a"]["vc"] ? $_COOKIE["w3a"]["vc"] : 1); @setcookie("w3a[vc]",$w3a_buf["vc"],time()+60*60*24*30,'/'); @setcookie("w3a[date]",time(),time()+60*60*24*30,'/'); } // http://カット if(strpos($w3a_buf["ref"], 'http://') === 0) $w3a_buf["ref"] = str_replace ('http://', "", $w3a_buf["ref"]); if(strpos($w3a_buf["ref"], $_SERVER["HTTP_HOST"]) === 0) $w3a_buf["ref"] = "[m]".str_replace ($_SERVER["HTTP_HOST"], "", $w3a_buf["ref"]); //前変換(毘溷化抑制) if($w3a_option["log_save"]){ unset($log_save); $log_save_fn = $acc_path."inc/save_list.php"; if(file_exists($log_save_fn)){ include_once($log_save_fn); $w3a_buf["ref"] = log_save_enc($log_save["ref"],$w3a_buf["ref"]); $w3a_buf["host"] = log_save_enc($log_save["host"],$w3a_buf["host"]); $w3a_buf["ua"] = log_save_enc($log_save["ua"],$w3a_buf["ua"],1); } } //追加モードで開く if($write_flg && $fn = fopen($w3a_logfile,"a+")){ //E充ド対E if($w3a_option["unwrite"]){ rewind($fn); while (!feof($fn)) { $str = trim(fgets($fn)); if($str == "") continue; list($tmp_data[dt],$tmp_data[path],$tmp_data[host],) = explode("\t",$str); if($tmp_data[dt]) list($tmp_data[day],$tmp_data[week],$tmp_data[hour],$tmp_data[minute],$tmp_data[sec]) = explode(",",$tmp_data[dt]); //TIME $write_time = time()-mktime($tmp_data[hour],$tmp_data[minute],$tmp_data[sec]); //指E丹幣紊覆藹了 if($w3a_option["unwrite"] < $write_time){ unset($tmp_data,$write_time); continue; } //PATH/HOSTチェック if($tmp_data[path] == $w3a_buf["path"] && $w3a_buf["host"] == $tmp_data[host]){ $write_flg = false; unset($tmp_data,$write_time); break; } } } //書き込み if($write_flg){ //書き込みバッファ0に PHP4.3以E if(function_exists('stream_set_write_buffer')) stream_set_write_buffer($fn, 0); //ファイE礎ク flock($fn,LOCK_EX); fwrite($fn,gmdate("d,D,H,i,s", time()+$time_diff*3600)); fwrite($fn,mk_data_w3a($w3a_buf["path"])); fwrite($fn,mk_data_w3a($w3a_buf["host"])); fwrite($fn,mk_data_w3a($w3a_buf["ref"])); fwrite($fn,mk_data_w3a($w3a_buf["ua"])); fwrite($fn,mk_data_w3a($w3a_buf["title"])); fwrite($fn,mk_data_w3a($w3a_buf["id"])); fwrite($fn,mk_data_w3a($w3a_buf["vc"])); fwrite($fn,"\n"); //礎ク解E flock($fn,LOCK_UN); } fclose($fn); } unset($w3a_buf,$w3a_logfile); } unset($acc_path,$w3a_option); } /*======================================*/ /* HTML用(1X1透明画E侘) */ /*======================================*/ if(isset($_GET["ref"])){ header("Content-Type: image/gif"); echo base64_decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="); exit; } ?>