'', 'platformV' => '', 'browser' => '', 'browserV' => ''); if(!isset($_SERVER['HTTP_USER_AGENT'])) { $_SERVER['HTTP_USER_AGENT'] = ''; } $ua = trim($_SERVER['HTTP_USER_AGENT']); $UA_SET = get_ua_set($ua); $UA_SET['browser'] .= '###' . trim($_SERVER['HTTP_USER_AGENT']); $UA_TYPE = isset($UA_SET['type']) ? $UA_SET['type'] : 'unknown'; $invalid_actype = false; if(!$config->ACTYPE_ALL) { if($UA_TYPE === 'pc' and !$config->ACTYPE_PC) { $invalid_actype = true; } elseif($UA_TYPE === 'm' and !$config->ACTYPE_M) { $invalid_actype = true; } elseif($UA_TYPE === 'c' and !$config->ACTYPE_C) { $invalid_actype = true; } elseif($UA_TYPE === 'unknown' and !$config->ACTYPE_U) { $invalid_actype = true; } } if($invalid_actype) { printImg(); exit; } $valid_params = array( 'PID' => true, 'PPID' => true, 'PTITLE' => true, 'ns' => true, 'TPRM' => true, 'SIN' => true, ); /** * strip parameters from query_string */ $strip_params = array( 'osCsid' => true, 'ktp' => true, 'UASEG' => true, 'tprm' => true, 'PHPSESSID' => true, ); foreach($valid_params as $param => $val) { if(!$val) { $_GET[$param] = ''; $_POST[$param] = ''; continue; } if(isset($_GET[$param])) { $_GET[$param] = $misc->sanitize_value($_GET[$param]); } elseif(isset($_POST[$param])) { $_GET[$param] = $misc->sanitize_value($_POST[$param]); } else { $_GET[$param] = ''; } } /** * user configuration */ $userconfig = new userConfig($config,$misc); // skip admin $ADMIN_SESSID_NAME = $config->ADMIN_SESSID_NAME; if(isset($_COOKIE[$ADMIN_SESSID_NAME])) { printImg(); exit; } // skip host,ip if(!isset($_SERVER['REMOTE_HOST'])) { $_SERVER['REMOTE_HOST'] = @gethostbyaddr($_SERVER['REMOTE_ADDR']); } if(isset($userconfig->config_skip_host[$_SERVER['REMOTE_ADDR']]) or isset($userconfig->config_skip_host[$_SERVER['REMOTE_HOST']])) { printImg(); exit; } else { foreach($userconfig->config_skip_host as $skip => $val) { if(ereg("\*",$skip)) { $skip = str_replace('*','',$skip); if(eregi($skip,$_SERVER['REMOTE_ADDR']) or eregi($skip,$_SERVER['REMOTE_HOST'])) { printImg(); exit; } } } } // noscript if($_GET['ns']) { if(!$_GET['PID']) { $_GET['PID'] = @getenv('HTTP_REFERER'); if(!$_GET['PID']) { $_GET['PID'] = $_SERVER['DOCUMENT_URI']; } } // if(!$_GET['PPID']) { $_GET['PPID'] = 'NO_SCRIPT'; } } // replacement $pid_rep = false; $ppid_rep = false; $pid_orig = $_GET['PID']; if($userconfig->config_rep_url) { foreach($userconfig->config_rep_url as $uri => $title) { if($pid_rep and $ppid_rep) { break; } if(empty($title)) { $title = 'REP_URL'; } if(!$pid_rep and ereg($uri,$_GET['PID'])) { $pid_purl = parse_url($_GET['PID']); // protocol added if(eregi("(http://|https://)",$config->SESSID_DOMAIN)) { $orig_purl = parse_url($config->SESSID_DOMAIN); if(!isset($orig_purl['path'])) { $orig_purl['path'] = ''; } $orig_host_dir = $orig_purl['host'] . $orig_purl['path']; $_GET['PID'] = ereg_replace($pid_purl['host'],$orig_host_dir . $title,$_GET['PID']); // pure domain } else { $_GET['PID'] = ereg_replace($pid_purl['host'],"{$config->SESSID_DOMAIN}/$title",$_GET['PID']); } $pid_rep = true; } if($_GET['PPID']) { if(!$ppid_rep and ereg($uri,$_GET['PPID'])) { $ppid_purl = parse_url($_GET['PPID']); // protocol added if(eregi("(http://|https://)",$config->SESSID_DOMAIN)) { $orig_purl = parse_url($config->SESSID_DOMAIN); if(!isset($orig_purl['path'])) { $orig_purl['path'] = ''; } $orig_host_dir = $orig_purl['host'] . $orig_purl['path']; $_GET['PPID'] = ereg_replace($ppid_purl['host'],$orig_host_dir . $title ,$_GET['PPID']); // pure domain } else { $_GET['PPID'] = ereg_replace($ppid_purl['host'],"{$config->SESSID_DOMAIN}/$title",$_GET['PPID']); } $ppid_rep = true; } } } } // //# now [PID] [PPID] fixed // // use get serank? $use_get_serank = false; if(isset($config->USE_GETSERANK) and $config->USE_GETSERANK === '1') { $use_get_serank = true; } // is valid page? if(!eregi($config->SESSID_DOMAIN,$_GET['PID'])) { printImg(); exit; } if($_GET['PID']) { $_GET['PID'] = strip_params_from_url($_GET['PID'],$strip_params); } if($_GET['PPID']) { $_GET['PPID'] = strip_params_from_url($_GET['PPID'],$strip_params); } // stime if(!$config->LTIMEOFFSET) { $config->LTIMEOFFSET = 0; } $stime = time() + (60*60*$config->LTIMEOFFSET); $date_info = @getdate($stime); // id issuing $sessid_expire = time() + 60*60*24*365; // 1-year expire Cookie $SESSID_NAME = 'XENOBEESESSID'; $ID_TOKEN = ''; if($_GET['TPRM']) { $ID_TOKEN = $_GET['TPRM']; } elseif(isset($_SERVER['HTTP_X_DCMGUID'])) { $ID_TOKEN = $_SERVER['HTTP_X_DCMGUID']; } elseif(isset($_SERVER['HTTP_X_UP_SUBNO'])) { $ID_TOKEN = $_SERVER['HTTP_X_UP_SUBNO']; } elseif(isset($_SERVER['HTTP_X_JPHONE_UID'])) { $ID_TOKEN = $_SERVER['HTTP_X_JPHONE_UID']; } elseif(preg_match("/^.+\/SN([0-9a-zA-Z]+).*$/",$_SERVER['HTTP_USER_AGENT'], $m)) { $ID_TOKEN = isset($m[1]) ? $m[1] : ''; } if(!$ID_TOKEN) { $ID_TOKEN = $_SERVER['REMOTE_ADDR']; } $last_visit_epoc = 0; $last_date_info = false; if(!isset($_COOKIE[$SESSID_NAME])) { // first access $SESSID = $ID_TOKEN . ' ' . microtime() . ' ' . $stime; @setcookie("$SESSID_NAME","$SESSID",$sessid_expire,"{$config->COOKIE_PATH}","{$config->COOKIE_DOMAIN}"); $VIS_TMP = true; } else { // cookie exists $tmp_array = explode(' ',$_COOKIE[$SESSID_NAME]); if(isset($tmp_array[0])) { $ID_TOKEN = $tmp_array[0]; } if(isset($tmp_array[3]) and !empty($tmp_array[3])) { $last_visit_epoc = $tmp_array[3]; $last_date_info = @getdate($last_visit_epoc); } $tmp_array[3] = $stime; $SESSID = implode(' ',$tmp_array); @setcookie("$SESSID_NAME","$SESSID",$sessid_expire,"{$config->COOKIE_PATH}","{$config->COOKIE_DOMAIN}"); } /** * * out put image * */ printImg(); // ppid $userCntrlUrl = $config->ANA_LOG_SCRIPT_URL; if(!empty($_GET['PPID'])) { if(@ereg($userCntrlUrl,$_GET['PPID'])) { $_GET['PPID'] = ''; } } //--- PID SKIP if(empty($_GET['PID'])) {exit;} //--- PPID SKIP if(ereg($config->GET_LOG_SCRIPT_NAME,$_GET['PPID'])) { exit;} if(!isset($_SERVER['HTTP_USER_AGENT'])) { $_SERVER['HTTP_USER_AGENT'] = 'unknown'; } /** * * Page Title * */ $page_title = rawurldecode($_GET['PTITLE']); $page_title_orig = $page_title; if(!$_GET['PTITLE'] or $_GET['PTITLE'] === 'undefined') { $page_title = '---'; if($page_title = $misc->get_page_title($pid_orig)) { //$page_title = mb_substr($page_title,0,40);// 40 length } else { $page_title = '---'; } } else { $enc = mb_detect_encoding($page_title,'auto'); if($enc != 'EUC-JP' and $enc != 'SJIS' and $enc != 'JIS' and $enc != 'UTF-8') { $page_title = uniDecode($page_title,$config->DBENCODING); } else { $page_title = @mb_convert_encoding($page_title,$config->DBENCODNG,'auto'); } } $page_title = strip_tags($page_title); $page_title = str_replace('<','',$page_title); $page_title = str_replace('>','',$page_title); //--- SearchEngine & KeyWords $EX_REF = false; $SESSION_IN = 0; $se_name = ''; $kword = ''; $rank = ''; if(!empty($_GET['PPID'])) { if(ereg("^h(ttp:|ttps:)",$config->SESSID_DOMAIN)) { // not original domain $parsed['host'] = $_GET['PPID']; } else { $parsed = parse_url($_GET['PPID']); } if(!ereg($config->SESSID_DOMAIN,$parsed['host'])) { $EX_REF = true; $SESSION_IN = 1; $SE_WORD = get_kword($config,$_GET['PPID'],$config->SESSID_DOMAIN,$use_get_serank); $se_name = $SE_WORD['se']; $kword = $SE_WORD['word']; $enc = ''; if(!empty($kword)) { $enc = mb_detect_encoding($kword); if($enc != $config->DBENCODING) { $kword = mb_convert_encoding($kword,$config->DBENCODING,$enc); } } $rank = $SE_WORD['rank']; } else { $EX_REF = false; $SESSION_IN = 0; $se_name = ''; $kword = ''; $rank = ''; } } else { $EX_REF = true; $SESSION_IN = 1; } if($_GET['SIN']) { $SESSION_IN = 1; } $_GET['PPID'] = ereg_replace(' ','+',$_GET['PPID']); // // raw log file $date = array(); $date = explode('-',date('Y-n-j-G',$stime)); $YEAR = $date[0]; $MONTH = $date[1]; $DAY = $date[2]; $HOUR = $date[3]; $LOG_DIR = $config->LOG_DIR; if(!is_dir($LOG_DIR)) { @mkdir($LOG_DIR,0777); } @chmod($LOG_DIR,0777); $lock_file = "{$LOG_DIR}/lock.cgi"; $LOCK = @fopen("{$lock_file}", "r+"); if( !$LOCK ) { $LOCK = fopen("{$lock_file}", "w"); } set_file_buffer($LOCK, 0); flock($LOCK, LOCK_EX); rewind($LOCK); $LBUF = fgets($LOCK, 1000000); if(!$LBUF) { $LBUF = 1;} else { $LBUF++;} // // file list // $log_actype = ''; if($UA_TYPE != 'pc' and $UA_TYPE != 'm') { $log_actype = 'c_'; } $fl_file = $LOG_DIR . '/' .str_replace(array('%actype%','year','month','day'),array($log_actype,$YEAR,$MONTH,$DAY),$config->FL_FILE_SKEL); if(file_exists($fl_file)) { $fl_cnt = trim(file_get_contents($fl_file)); $log_file = $LOG_DIR . '/' . $config->RAW_LOG_FILE_HEAD . $log_actype . $YEAR . '-' . $MONTH . '-' . $DAY .'_'. $fl_cnt . $config->LOG_FILE_FOOT; } else { $fl_cnt = 1; $log_file = $LOG_DIR . '/' . $config->RAW_LOG_FILE_HEAD . $log_actype . $YEAR . '-' . $MONTH . '-' . $DAY .$config->LOG_FILE_FOOT; } $row_cnt = 0; if(file_exists($log_file)) { $row_cnt = count(file($log_file)); } if($row_cnt >= $config->MAX_LOG_ROWS) { $fl_cnt++; $insert_log_file = $LOG_DIR . '/' . $config->RAW_LOG_FILE_HEAD . $log_actype . $YEAR . '-' . $MONTH . '-' . $DAY .'_'. $fl_cnt . $config->LOG_FILE_FOOT; if($fp = @fopen($fl_file,'w')) { set_file_buffer($fp, 0); flock($fp, LOCK_EX); rewind($fp); fwrite($fp,$fl_cnt); flock($fp, LOCK_UN); fclose($fp); @chmod($fl_file,0666); } } else { $insert_log_file = $log_file; } $insert_data = ''; $insert_data_array = array( $stime, $SESSID, $_SERVER['REMOTE_ADDR'], $_SERVER['REMOTE_HOST'], $_GET['PID'], $_GET['PPID'], $UA_SET['platform'], $UA_SET['platformV'], $UA_SET['browser'], $UA_SET['browserV'], $page_title, $se_name, $kword, $rank, $UA_TYPE, $SESSION_IN, date('Y-n-j H:i:s',$stime)); $insert_data_array = str_replace("\r\n","\n",$insert_data_array); $insert_data_array = str_replace("\n","",$insert_data_array); $insert_data_array = str_replace($config->LOG_DLMTR,"",$insert_data_array); $insert_data = implode($config->LOG_DLMTR,$insert_data_array); $insert_data .= "\n"; include_once 'svis_host.php'; $svis_log_file = $LOG_DIR . '/' . $config->SVIS_LOG_FILE_HEAD . $YEAR . '-' . $MONTH . '-' . $DAY . $config->LOG_FILE_FOOT; $dpv_log_file = $config->DPV_LOG_FILE_HEAD . $log_actype . $YEAR . '-' . $MONTH . $config->LOG_FILE_FOOT; $mpv_log_file = $config->MPV_LOG_FILE_HEAD . $log_actype . $YEAR . $config->LOG_FILE_FOOT; $se_log_file = $config->SE_LOG_FILE_HEAD . $log_actype . $YEAR . $config->LOG_FILE_FOOT; $dse_log_file = $config->SE_LOG_FILE_HEAD . $log_actype . $YEAR . '-' . $MONTH . $config->LOG_FILE_FOOT; $LOCK_DIR = "$LOG_DIR/LOCK"; if(!file_exists("$LOG_DIR/$dpv_log_file")) { touch("$LOG_DIR/$dpv_log_file"); $dpv_init = true; @chmod("$LOG_DIR/$dpv_log_file",0666); } else { $dpv_init = false; @chmod("$LOG_DIR/$dpv_log_file",0666); } if(!file_exists("$LOG_DIR/$mpv_log_file")) { touch("$LOG_DIR/$mpv_log_file"); $mpv_init = true; @chmod("$LOG_DIR/$mpv_log_file",0666); } else { $mpv_init = false; @chmod("$LOG_DIR/$mpv_log_file",0666); } if($se_name) { if(!file_exists("$LOG_DIR/$se_log_file")) { touch("$LOG_DIR/$se_log_file"); $se_init = true; @chmod("$LOG_DIR/$se_log_file",0666); } else { $se_init = false; @chmod("$LOG_DIR/$se_log_file",0666); } if(!file_exists("$LOG_DIR/$dse_log_file")) { touch("$LOG_DIR/$dse_log_file"); $dse_init = true; @chmod("$LOG_DIR/$dse_log_file",0666); } else { $dse_init = false; @chmod("$LOG_DIR/$dse_log_file",0666); } } else { $se_init = false; $dse_init = false; } $svisit = false; /** * * visitor check * in Cookie values * */ if($last_date_info) { // maybe repeated today if($date_info['year'] == $last_date_info['year'] and $date_info['mon'] == $last_date_info['mon'] and $date_info['mday'] == $last_date_info['mday']) { $svisit = false; } else { if(file_exists($svis_log_file)) { if($nc_file_array = file($svis_log_file)) { $ip_array = explode(' ',$nc_file_array[0]); $ip_cnt = array_count_values($ip_array); if(!isset($ip_cnt[$ID_TOKEN])) { save_svis_host($svis_log_file,$ID_TOKEN); $svisit = true; } else { $svisit = false; } } } else { $svisit = true; save_svis_host($svis_log_file,$ID_TOKEN); } } } else { if(file_exists($svis_log_file)) { if($nc_file_array = file($svis_log_file)) { $ip_array = explode(' ',$nc_file_array[0]); $ip_cnt = array_count_values($ip_array); if(!isset($ip_cnt[$ID_TOKEN])) { save_svis_host($svis_log_file,$ID_TOKEN); $svisit = true; } else { $svisit = false; } } } else { $svisit = true; // ID_TOKEN 保存 save_svis_host($svis_log_file,$ID_TOKEN); } } /** * * raw: per day * */ // raw data first! if($fp = fopen($insert_log_file,'a')) { set_file_buffer($fp, 0); flock($fp, LOCK_EX); rewind($fp); fwrite($fp,$insert_data); flock($fp, LOCK_UN); fclose($fp); @chmod($insert_log_file,0666); } /** * * dpv: per day * */ // format: {0..31},pv_total,{0..31},svis_total if($dpv_init) { // {0 0 0 ...0},pv_total,{0 0 0 ...0},vis_total\n $pv_day = array_fill(0,32,0); $svis_day = array_fill(0,32,0); $pv_day[$DAY]++; if($svisit) { $svis_day[$DAY]++; } $pv_day_line = implode(' ',$pv_day); $svis_day_line = implode(' ',$svis_day); $dpv_data = $pv_day_line . ',' . 1 . ',' . $svis_day_line . ','; if($svisit) { $dpv_data .= 1 . "\n"; } else { $dpv_data .= 0 . "\n"; } if($fp = fopen("$LOG_DIR/$dpv_log_file",'a')) { set_file_buffer($fp, 0); flock($fp, LOCK_EX); fwrite($fp,$dpv_data); flock($fp, LOCK_UN); fclose($fp); } } else { unset($new_data,$found); $new_data = ''; $found = false; if($file_array = file("$LOG_DIR/$dpv_log_file")) { $line = $file_array[0]; $line = rtrim($line); $line_array = explode(',',$line); $io_op = 'w'; $found = true; $pv_total = $line_array[1]; $pv_total++; $svis_total = $line_array[3]; $pv_day = explode(' ',$line_array[0]); $svis_day = explode(' ',$line_array[2]); if($svisit) { $svis_day[$DAY]++; $svis_total++; } $pv_day[$DAY]++; $pv_day_line = implode(' ',$pv_day); $svis_day_line = implode(' ',$svis_day); $line = $pv_day_line . ',' . $pv_total . ',' . $svis_day_line . ',' . $svis_total; $new_data .= $line . "\n"; } else { $io_op = 'w'; $pv_day = array_fill(0,32,0); $svis_day = array_fill(0,32,0); $pv_day[$DAY]++; $vis_day[$DAY]++; if($svisit) { $svis_day[$DAY]++; } $pv_day_line = implode(' ',$pv_day); $svis_day_line = implode(' ',$svis_day); $new_data = $pv_day_line . ',' . 1 . ',' . $svis_day_line . ','; if($svisit) { $new_data .= 1 . "\n"; } else { $new_data .= 0 . "\n"; } } if($fp = fopen("$LOG_DIR/$dpv_log_file","$io_op")) { set_file_buffer($fp, 0); flock($fp, LOCK_EX); rewind($fp); fwrite($fp,$new_data); flock($fp, LOCK_UN); fclose($fp); } } /** * * mpv: per month * */ if($mpv_init) { // pv_mon vis_mon // {1 ...12},pv_total,{1...12},vis_total\n $pv_mon = array_fill(0,13,0); $svis_mon = array_fill(0,13,0); $pv_mon[$MONTH] = 1; $vis_mon[$MONTH] = 1; if($svisit) { $svis_mon[$MONTH] = 1; } $pv_mon_line = implode(' ',$pv_mon); $svis_mon_line = implode(' ',$svis_mon); $mpv_data = $pv_mon_line . ',' . 1 . ',' . $svis_mon_line . ','; if($svisit) { $mpv_data .= 1 . "\n"; } else { $mpv_data .= 0 . "\n"; } if($fp = fopen("$LOG_DIR/$mpv_log_file",'w')) { set_file_buffer($fp, 0); flock($fp, LOCK_EX); fwrite($fp,$mpv_data); flock($fp, LOCK_UN); fclose($fp); } } else { $new_data = ''; $found = false; if($file_array = file("$LOG_DIR/$mpv_log_file")) { $line = $file_array[0]; $line = rtrim($line); $line_array = explode(',',$line); $io_op = 'w'; $pv_total = $line_array[1]; $pv_total++; $svis_total = $line_array[3]; $pv_mon = explode(' ',$line_array[0]); $svis_mon = explode(' ',$line_array[2]); if($svisit) { $svis_mon[$MONTH]++; $svis_total++; } $pv_mon[$MONTH]++; $pv_mon_line = implode(' ',$pv_mon); $svis_mon_line = implode(' ',$svis_mon); $line = $pv_mon_line . ',' . $pv_total . ',' . $svis_mon_line . ',' . $svis_total; $new_data .= $line . "\n"; } else { $io_op = 'w'; $pv_mon = array_fill(0,13,0); $svis_mon = array_fill(0,13,0); $pv_mon[$MONTH]++; $vis_mon[$MONTH]++; if($svisit) { $svis_mon[$MONTH]++; } $pv_mon_line = implode(' ',$pv_mon); $svis_mon_line = implode(' ',$svis_mon); $new_data = $pv_mon_line . ',' . 1 . ',' . $svis_mon_line . ','; if($svisit) { $new_data .= 1 . "\n"; } else { $new_data .= 0 . "\n"; } } if($fp = fopen("$LOG_DIR/$mpv_log_file","$io_op")) { set_file_buffer($fp, 0); flock($fp, LOCK_EX); rewind($fp); fwrite($fp,$new_data); flock($fp, LOCK_UN); fclose($fp); } } /** * * se: per month * */ if($se_init and !empty($se_name)) { // pv vis // se_name,{0 0 0 ...0},pv_total\n $pv = array_fill(0,13,0); $pv[$MONTH]++; $pv_line = implode(' ',$pv); $se_data = $se_name . ',' .$pv_line . ',1' . "\n"; if($fp = fopen("$LOG_DIR/$se_log_file",'a')) { set_file_buffer($fp, 0); flock($fp, LOCK_EX); fwrite($fp,$se_data); flock($fp, LOCK_UN); fclose($fp); } } elseif(!empty($se_name)) { $new_data = ''; $found = false; if($file_array = file("$LOG_DIR/$se_log_file")) { foreach($file_array as $line) { $line = rtrim($line); $line_array = explode(',',$line); if($line_array[0] === $se_name) { $found = true; $io_op = 'w'; $pv_total = $line_array[2]; $pv_total++; $pv = explode(' ',$line_array[1]); $pv[$MONTH]++; $pv_line = implode(' ',$pv); $line = $se_name . ',' .$pv_line . ',' .$pv_total; } $new_data .= $line . "\n"; } if(!$found) { $io_op = 'a'; $pv = array_fill(0,13,0); $pv[$MONTH]++; $pv_line = implode(' ',$pv); $new_data = $se_name . ',' .$pv_line . ',1'."\n"; } } else { $io_op = 'w'; $pv = array_fill(0,13,0); $pv[$MONTH]++; $pv_line = implode(' ',$pv); $new_data = $se_name . ',' . $pv_line . ',' . 1 . "\n"; } if($fp = fopen("$LOG_DIR/$se_log_file","$io_op")) { set_file_buffer($fp, 0); flock($fp, LOCK_EX); rewind($fp); fwrite($fp,$new_data); flock($fp, LOCK_UN); fclose($fp); } } /** * * dse: per day * */ if($dse_init and !empty($se_name)) { // pv vis // se_name,{0 0 0 ...0},pv_total\n $pv = array_fill(0,32,0); $pv[$DAY]++; $pv_line = implode(' ',$pv); $se_data = $se_name . ',' .$pv_line . ',1' . "\n"; if($fp = fopen("$LOG_DIR/$dse_log_file",'a')) { set_file_buffer($fp, 0); flock($fp, LOCK_EX); fwrite($fp,$se_data); flock($fp, LOCK_UN); fclose($fp); } } elseif(!empty($se_name)) { $new_data = ''; $found = false; if($file_array = file("$LOG_DIR/$dse_log_file")) { foreach($file_array as $line) { $line = rtrim($line); $line_array = explode(',',$line); if($line_array[0] === $se_name) { $found = true; $io_op = 'w'; $pv_total = $line_array[2]; $pv_total++; $pv = explode(' ',$line_array[1]); $pv[$DAY]++; $pv_line = implode(' ',$pv); $line = $se_name . ',' .$pv_line . ',' .$pv_total; } $new_data .= $line . "\n"; } if(!$found) { $io_op = 'a'; $pv = array_fill(0,32,0); $pv[$DAY]++; $pv_line = implode(' ',$pv); $new_data = $se_name . ',' .$pv_line . ',1'."\n"; } } else { $io_op = 'w'; $pv = array_fill(0,32,0); $pv[$DAY]++; $pv_line = implode(' ',$pv); $new_data = $se_name . ',' . $pv_line . ',' . 1 . "\n"; } if($fp = fopen("$LOG_DIR/$dse_log_file","$io_op")) { set_file_buffer($fp, 0); flock($fp, LOCK_EX); rewind($fp); fwrite($fp,$new_data); flock($fp, LOCK_UN); fclose($fp); } } rewind($LOCK); fputs($LOCK, $LBUF); flock($LOCK, LOCK_UN); fclose($LOCK); /** * * for encoded string by javascript * */ function uniDecode($str,$charcode) { $text = preg_replace_callback("/%u[0-9A-Za-z]{4}/",'toUtf8',$str); return mb_convert_encoding($text, $charcode, 'utf-8'); } function toUtf8($ar) { $c = ''; foreach($ar as $val){ $val = intval(substr($val,2),16); if($val < 0x7F){ // 0000-007F $c .= chr($val); }elseif($val < 0x800) { // 0080-0800 $c .= chr(0xC0 | ($val / 64)); $c .= chr(0x80 | ($val % 64)); }else{ // 0800-FFFF $c .= chr(0xE0 | (($val / 64) / 64)); $c .= chr(0x80 | (($val / 64) % 64)); $c .= chr(0x80 | ($val % 64)); } } return $c; } /** * * strip params: see $strip_params -- the top of this file. * */ function strip_params_from_url($url = false,$strip_params = false) { if(!$strip_params) { return $url; } $valid_url = $url;// init if(!$parsed_item = @parse_url($url)) { return false; } if(!isset($parsed_item['path'])) { $parsed_item['path'] = ''; } $valid_qstr_array = array(); if(isset($parsed_item['query'])) { $query_array = explode('&',$parsed_item['query']); if($query_array) { foreach($query_array as $qstr) { $param = explode('=',$qstr); if(!isset($strip_params[$param[0]])) { array_push($valid_qstr_array,$qstr); } elseif(!$strip_params[$param[0]]) { array_push($valid_qstr_array,$qstr); } } $valid_qstr = '?' . implode('&',$valid_qstr_array); } else { $valid_qstr = $parsed_item['query']; } $valid_url = $parsed_item['scheme'] . '://' . $parsed_item['host'] . $parsed_item['path'] . $valid_qstr; } return $valid_url; } /** * * image: if noscript * */ function printImg() { global $config; if(isset($_GET['META'])) {return;} header ('Content-type: image/gif'); $img = $config->IMGS['analytics']; $fp = fopen($img,'rb'); $bimg = fread($fp,filesize($img)); print $bimg; return; } exit; ?>