애플리케이션, 세부 웹사이트페이지 등 간단하게 시간별, 일자별 등으로 확인할 카운터가 필요한데,
대부분 카운터들이 레퍼값, 에이젼트값 등등 애플리케이션에선 굳이 필요없는것들이 많고, 접속할때마다
레코드가 생성됨으로 괜한 DB 용량만 늘어나기에 간단하게 만들게 되었다.
* 구조
config.php - DB 커넥션을 위한것임
maketable.php - DB 테이블 생성(처음 1회 필요)
count.php - 카운터 생성(img 태그등으로 0x0 픽셀로 함 되고 아님 필요한 소스에 알아서 넣음됨)
view.php - 카운터 뷰(간단한 형식으로 되어 있어서 필요시 파싱해서 쓰면 됨)
* 실행방법
1. config.php 에 자신의 DB 정보를 기입
2. 처음 카운터를 생성시 "maketable.php?id=카운터명"
3. 필요한 곳에 "count.php?id=카운터명" 를 이용
4. 카운터 볼때 "view.php?id=카운터명" 을 이용
* 소스 : config.php
<?
//////////////////////////////////////////////////////////
// Subject : Simple Counter
// File : config.php
// Date : 2008/8/11
// Name : Oh Kilho(prince@kilho.net)
// Home : http://www.kilho.net
//////////////////////////////////////////////////////////
$host='';
$user='';
$password='';
$dataname='';
$db=mysql_connect($host,$user,$password);
mysql_select_db($dataname,$db);
$id=$_GET['id'];
if(!$id)exit;
?>
* 소스 : maketable.php
<?
//////////////////////////////////////////////////////////
// Subject : Simple Counter
// File : maketable.php
// Date : 2008/8/11
// Name : Oh Kilho(prince@kilho.net)
// Home : http://www.kilho.net
//////////////////////////////////////////////////////////
include 'config.php';
$my_query="
CREATE TABLE IF NOT EXISTS `cnt_$id` (
`date` date NOT NULL,
`h00` int(11) NOT NULL,
`h01` int(11) NOT NULL,
`h02` int(11) NOT NULL,
`h03` int(11) NOT NULL,
`h04` int(11) NOT NULL,
`h05` int(11) NOT NULL,
`h06` int(11) NOT NULL,
`h07` int(11) NOT NULL,
`h08` int(11) NOT NULL,
`h09` int(11) NOT NULL,
`h10` int(11) NOT NULL,
`h11` int(11) NOT NULL,
`h12` int(11) NOT NULL,
`h13` int(11) NOT NULL,
`h14` int(11) NOT NULL,
`h15` int(11) NOT NULL,
`h16` int(11) NOT NULL,
`h17` int(11) NOT NULL,
`h18` int(11) NOT NULL,
`h19` int(11) NOT NULL,
`h20` int(11) NOT NULL,
`h21` int(11) NOT NULL,
`h22` int(11) NOT NULL,
`h23` int(11) NOT NULL,
`total` int(11) NOT NULL,
PRIMARY KEY (`date`)
) ENGINE=MyISAM DEFAULT CHARSET=euckr;
";
mysql_query($my_query);
mysql_close();
?>
* 소스 : count.php
<?
//////////////////////////////////////////////////////////
// Subject : Simple Counter
// File : config.php
// Date : 2008/8/11
// Name : Oh Kilho(prince@kilho.net)
// Home : http://www.kilho.net
//////////////////////////////////////////////////////////
$host='localhost';
$user='cnt';
$password='cjstk';
$dataname='cnt';
$db=mysql_connect($host,$user,$password);
mysql_select_db($dataname,$db);
$id=$_GET['id'];
if(!$id)exit;
?>
소스 : view.php
<?
//////////////////////////////////////////////////////////
// Subject : Simple Counter
// File : view.php
// Date : 2008/8/11
// Name : Oh Kilho(prince@kilho.net)
// Home : http://www.kilho.net
//////////////////////////////////////////////////////////
include 'config.php';
$my_query="select * from cnt_$id";
$result=mysql_query($my_query);
while($row=mysql_fetch_array($result))
{
echo '<data id="'.$row[date].'">';
for($i=0;$i<24;$i++)
{
echo $row[(sprintf("h%02d",$i))].'^';
}
echo $row[total];
echo '</data>'."\n";
}
mysql_close();
?>







Prev