--JAVAscriptで呼び出すカウンタスクリプト --Tanaka's OSAX 2.01が必要です。 --ver0.1 2003/11/30 最初のバージョン --ver0.2 2003/12/1 カウントファイル名の指定が可能に。例:counter.acgi?cntFile=indexCount2 --ver0.3 2003/12/2 未公開。IPアドレスの重複をチェックして、同じIPからのアクセスの場合、カウントアップしない。 --ver0.31 2003/12/2 IP保存ファイルの判定部にバグ発覚。その日のIP保存ファイルどうかで削除判定するように変更。 --ver0.32 2006/9/25 IP保存ファイルの有効/無効判定を高速化。カウントアップハンドラの無駄な動きを削除。 property thisDir : "" --スクリプトのあるディレクトリが入る property countFile : "" --カウントファイル名 property iplog : "_ip" -- ★★★ IP保存ファイル名。空白にするとIPチェックしない。 ★★★--------------設定必須 property crlf : (ASCII character 13) & (ASCII character 10) on run set thisDir to (":" as alias) as string --パス取得 --自動取得↑がうまくいかない場合は↓手動で設定してね。 --set thisDir to "" --スクリプトのあるパス end run on handle CGI request urlPath searching for getData with posted data postData from client IP address ipAddress --受けた引数を一本化 if (postData as text) = "" then set postGetData to getData as text else set postGetData to postData as text end if set countFile to "indexCount" -- ★★★ カウントファイル名初期化 ★★★--------------設定必須 if postGetData ュ "" then --空でなければ --中身を分解して引数を取り出す。OSAX使用 set {cntFile} to MT Parse CGI postGetData --cntFileを取り出す set countFile to cntFile --カウントファイル名を差し替え end if if iplog ュ "" then --IPファイル名が空でないならIPチェック set today to current date set time of today to 0 -- 今日の0時丁度に設定 try set ipFileDate to MT Get Info file (thisDir & countFile & iplog) about creation_date --ファイルがないとエラーとなる if ipFileDate < today then --昨日以前だ。つまり本日最初のアクセス。 tell application "Finder" delete file (thisDir & countFile & iplog) --ゴミ箱に移して empty trash --ゴミ箱を空にする end tell my countUp(1) --カウントアップと表示 else -- >=の場合。今日だ try set ipData to (MT Read File (thisDir & countFile & iplog)) --IPファイルを読み込んで set ipUmu to MT Search Position ipData search ipAddress --IPアドレスがあるか調べる。なければ空、あれば1以上の整数が返る。 on error errorNum --IPファイルがなかったら set ipUmu to "" end try --IPチェックを行う if ipUmu as text ウ 1 then --IPがあった my countUp(0) --表示のみ else --IPがなかった --IPアドレスを追記 MT Write File (ipAddress & return) to file (thisDir & countFile & iplog) with appending my countUp(1) --カウントアップと表示 end if end if on error errorNum --エラーがでるということはIPファイルがないのであった。ファイル作成 MT Write File (ipAddress & return) to file (thisDir & countFile & iplog) with appending my countUp(1) --カウントアップと表示 end try else --IPチェックをしないなら my countUp(1) --カウントアップと表示 end if end handle CGI request --カウントアップ処理 --mode0なら表示だけ。1ならカウントアップする on countUp(mode) --カウントアップ try set thisnum to (MT Read File (thisDir & countFile)) --カウンタファイルの読込 if mode = 1 then --カウントアップなら set thisnum to thisnum + 1 MT Write File thisnum to file (thisDir & countFile) --カウンタファイルに上書き else --カウントアップしないなら --なんもしない end if on error errorNum --ファイルがなかったら set thisnum to 1 MT Write File (thisnum) to file (thisDir & countFile) --カウンタファイル作成 end try --表示処理 set retJava to "document.write('" & thisnum & "');" & crlf return retJava end countUp