" ); } // brew.ne.jpからのアクセスだけを許可する場合は以下の通り $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']); if( FALSE == strstr( $hostname, "ezweb.ne.jp" ) ) { exit( "点数はアプリから登録してください。" ); } // スコアファイルの読み出し $nIndex = 0; if( !file_exists( $scoreFile ) ) { touch( $scoreFile ); } if( $aryIndex = file( $scoreFile ) ) { // 重複したレコードの削除 foreach( $aryIndex as $strLine ) { $strLine = trim( $strLine ); list( $tmp_score, $tmp_id ) = explode( ",", $strLine, 1000 ); if( 0 == strcmp($tmp_id, $subid) ) {// 既に登録されているIDだった // 配列から削除 array_splice( $aryIndex, $nIndex, 1 ); break; } else { $x = strcmp($tmp_id, $subid); } $nIndex++; } } // 新しい行の追加 $strNewLine = $fscore.",".$subid; $aryIndex[] = $strNewLine; reset( $aryIndex ); // 点数順にソート usort( $aryIndex, "cmp_score" ); reset( $aryIndex ); if( $hFile = fopen( $scoreFile, "w" ) ) { foreach( $aryIndex as $strLine ) { $strLine = trim( $strLine ); fwrite( $hFile, $strLine."\n", 1000 ); } fclose( $hFile ); } else { exit( "アクセスが集中しています。しばらくしてから再登録をお願い致します。" ); } // ここまででランキングリストが完成 // 順位の表示 reset( $aryIndex ); $nIndex = 1; foreach( $aryIndex as $strLine ) { list( $tmp_score, $tmp_id ) = explode( ",", $strLine, 1000 ); if( 0 != strcmp($tmp_id, $subid) ) { $nIndex++; } else { break; } } $count_all = count($aryIndex); print "現在のあなたの順位は $count_all 人中 $nIndex 位です。
"; print '本体サイトへ
'; reset( $aryIndex ); $nIndex = 1; foreach( $aryIndex as $strLine ) { list( $tmp_score, $tmp_id ) = explode( ",", $strLine, 1000 ); if( $nIndex <= 20 ) { // 20位まで表示 print "$nIndex 位 : $tmp_score 点
"; $nIndex++; } else { break; } } ?>