$val ) { print "$key : $val
"; } } else { exit( "Thank you." ); } break; case 'daytotal': if ( chkAllow() ) { totalCalc( "$logfile", $uri[4] ); foreach( $cntday as $key => $val ) { print "$key : $val
"; } } else { exit( "Thank you." ); } break; case 'dltotal': if ( chkAllow() ) { $cnt = totalAll( "$logfile" ); foreach( $cnt as $key => $val ) { $out .= "$key,$val\n"; } $file = fopen( "tmp.csv", "w" ) or die( '書き込みエラー
' ); flock( $file, LOCK_EX ); fputs( $file, $out ); flock( $file, LOCK_UN ); fclose( $file ); downloadFile( "tmp.csv", "$id.csv" ); } else { exit( "Thank you." ); } break; default: exit( '指定に誤りがあります' ); break; } function dispAdmin( $setup ) { /* if ( $handle = opendir( $aDir ) ) { while ( false !== ( $file = readdir( $handle ) ) ) { if ( $file != "." && $file != ".." ) { $option .= "\n"; } } closedir($handle); } */ foreach( $setup as $val ) { $val = preg_replace( "/\r\n|\r|\n/", "", $val ); if ( !preg_match( "/^#/", $val ) ) { list( $id, $url, $outfile ) = explode( ",", $val ); $option .= "\n"; } } $host = $_SERVER['HTTP_HOST']; print << リダイレクトカウント
HTML; } function totalAll( $aFile ) { global $cntday; $rec = file( $aFile ); foreach( $rec as $val ) { list( $date, $host ) = explode( ",", $val ); list( $day, $time ) = explode( " ", $date ); $cntday[$day]++; } ksort( $cntday ); return $cntday; } function totalCalc( $aFile, $aMon = "" ) { global $cntday, $cntmon; $rec = file( $aFile ); foreach( $rec as $val ) { list( $date, $host ) = explode( ",", $val ); list( $day, $time ) = explode( " ", $date ); $ymd = explode( "/", $day ); $cntmon[$ymd[0].'-'.$ymd[1]]++; if ( $aMon ) { if ( ( $ymd[0].'-'.$ymd[1] ) === $aMon ) { $cntday[$day]++; } } } if ( $aMon ) { ksort( $cntday ); } else { ksort( $cntmon ); } //return $cnt; } function redirectURL( $aFile, $aUrl ) { $data = date( "Y/m/d H:i:s" ).','.( $_SERVER['REMOTE_HOST'] ? $_SERVER['REMOTE_HOST'] : $_SERVER['REMOTE_ADDR'] ).','.$_SERVER['HTTP_REFERER']."\n"; $file = fopen( "$aFile", "a" ) or die( '書き込みエラー
' ); flock( $file, LOCK_EX ); fputs( $file, $data ); flock( $file, LOCK_UN ); fclose( $file ); chmod( "$aFile", 0666 ); header( "Location: http://$aUrl" ); } function downloadFile( $aFile, $aRename="" ) { $file = "$aFile"; if ( ( $content_length = filesize( $file ) ) == 0 ) { die( "Error: File size is 0." ); } if ( $aRename ) $aFile = $aRename; Header( "Content-Disposition: attachment; filename=$aFile" ); header( "Content-Length: ".$content_length ); Header( "Content-Type: application/octet-stream; name=$aFile" ); if ( !readfile( $file ) ) { die( "Cannot read the file" ); } } ?>