간단한 PHP 파일 카운트 소스입니다.

아래 내용을 메모장에 복사-붙여넣기 해서 counter.php 로 저장합니다.

counter.php 파일은 서버로 ASCII 모드로 업로드 하고, 권한을 777로 설정합니다. 빈 index.php.dat 파일을 만들어 index.php 가 위치하는 경로에 업로드 하고, 권한을 777로 설정합니다.

접속한 페이지가 text.php 이면 text.php.dat 이 되고, 접속한 페이지가 order.php 이면 order.php.dat 라는 빈 파일을 만들어 서버로 업로드해 줍니다.

각 dat 파일은 페이지별 통계를 구하기 위해 만들어 주는 것입니다.

<?php
 $cfile = basename($_SERVER['PHP_SELF']) . ".dat";
 $fh = fopen($cfile, "r+");
 if (!$fh) {
   die("<br/>Failed to open file.");
 }
 $s = fgets($fh, 6);
 $count = (int)$s;
 $count = $count + 1;
 $count = str_pad($count, 6);
 rewind($fh);
 fwrite($fh, $count);

 echo "<center>$count visitors to this webpage</center>";
 fclose($fh);
 ?>

다음 내용을 각 페이지에 삽입하여 줍니다.

<?php include "counter.php" ?>

0 댓글