<?
//홈페이지 상단에 아래 부분만 붙이면 됩니다.
========== 시작 ============
include '/Visit.php';
session_start();
$visit = new Visit($dbconn);
$visit->listenVisit();
$visit_total = $visit->getVisit(); //전체 방문자
$visit_today = $visit->getVisit(date('Y'),date('n'),date('j')); //오늘방문자
unset($visit);
========== 끝 ============
아래는 클래스 파일입니다.
========================
- class.Visit.php
========================
/* 방문자 기록 관리 클래스 */
Class Visit
{
var $dbconn;
var $sql;
var $error_msg;
function Visit($dbconn){
$this->dbconn = $dbconn;
}
/*방문자 추출 메소드 */
function getVisit($syear='', $smonth='', $sday=''){
if($syear == '' && $smonth == '' && $sday == ''){
$this->sql = "select sum(hit) as hit from visit "; //총방문자 수
}
else {
$this->sql = "select hit from visit ";
if($syear != "")
$this->sql .= "where syear='$syear' ";
if($smonth != "")
$this->sql .= "and smonth='$smonth' ";
if($sday != "")
$this->sql .= "and sday='$sday' ";
}
$result = mysql_query($this->sql, $this->dbconn);
if($result){
if(mysql_num_rows($result))
return mysql_result($result,0,'hit');
else
return 0;
}
else {
$this->error_msg = mysql_error();
return 0;
}
}
function addVisit($syear, $smonth, $sday){
$this->sql = "insert into visit(syear, smonth, sday, hit)
values('$syear', '$smonth', '$sday', 1)";
$result = mysql_query($this->sql, $this->dbconn);
if($result)
return true;
else {
$this->error_msg = mysql_error();
return false;
}
}
function upVisit(){
$syear = date('Y');
$smonth = date('n');
$sday = date('j');
$is_data = $this->isVisit($syear, $smonth, $sday);
if($is_data)
$this->editVisit($syear, $smonth, $sday);
else
$this->addVisit($syear, $smonth, $sday);
}
function editVisit($syear, $smonth, $sday){
$this->sql = "update visit set hit=hit+1
where syear='$syear' and smonth='$smonth' and sday='$sday'";
$result = mysql_query($this->sql, $this->dbconn);
if($result)
return true;
else {
$this->error_msg = mysql_error();
return false;
}
}
function delVisit($uid){
$this->sql = "delete from visit where uid=$uid";
$result = mysql_query($this->sql, $this->dbconn);
if($result)
return true;
else {
$this->error_msg = mysql_error();
return false;
}
}
function isVisit($syear, $smonth, $sday){
$this->sql = "select uid from visit
where syear='$syear' and smonth='$smonth' and sday='$sday'";
$result = mysql_query($this->sql, $this->dbconn);
if($result){
if(mysql_num_rows($result))
return 1;
else
return 0;
}
else {
$this->error_msg = mysql_error();
return 1;
}
}
function listVisit($pageInfo, $syear='', $smonth='', $sday=''){
$this->sql = "select syear, smonth, sday, hit
from visit ";
if($syear != '') $this->sql .= " where syear='$syear'";
if($smonth != '') $this->sql .= " and smonth='$smonth'";
if($sday != '') $this->sql .= " and sday='$sday'";
$this->sql .= " order by syear desc, smonth desc, sday desc";
$result = mysql_query($this->sql, $this->dbconn);
if($result){
$j=0;
for($i=$pageInfo["first"]; $i<=$pageInfo["last"]; $i++){
$info["num"][$j] = $pageInfo["cnt"] - $i;
$info["syear"][$j] = mysql_result($result,$i,"syear");
$info["smonth"][$j] = mysql_result($result,$i,"smonth");
$info["sday"][$j] = mysql_result($result,$i,"sday");
$info["hit"][$j] = mysql_result($result,$i,"hit");
$j++;
}
return $info;
}
else {
$this->error_msg = mysql_error();
return false;
}
}
/* 20분 기준 방문자 체크 메소드 */
function listenVisit(){
$now_visit_date = mktime(date('H'),date('i'),0,date('m'),date('d'),date('Y'));
if($_COOKIE['visit_date'] != ''){
$old_visit_date = $_COOKIE['visit_date'];
$is_first = false;
}
else {
$old_visit_date = $now_visit_date;
setcookie('visit_date', $now_visit_date);
$is_first = true;
}
$diff_date = $now_visit_date - $old_visit_date;
if($diff_date > 1200 || $is_first == true){ //20분 응답 60 * 20
setcookie('visit_date', $now_visit_date);
$this->upVisit();
}
}
function getCnt($syear='', $smonth='', $sday=''){
$this->sql = "select count(uid) as cnt from visit";
if($syear != '') $this->sql .= " where syear='$syear'";
if($smonth != '') $this->sql .= " and smonth='$smonth'";
if($sday != '') $this->sql .= " and sday='$sday'";
$result = mysql_query($this->sql, $this->dbconn);
if($result){
$cnt = mysql_result($result,0,"cnt");
return $cnt;
}
else {
$this->error_msg = mysql_error();
return 0;
}
}
/* error를 출력하는 메소드 */
/* filter 0-error발생시 출력, 1-무조건 출력 */
function printErr($filter=0){
if($this->error_msg != '' || $filter == 1){
echo '<br>'.$this->sql;
echo '<br>'.$this->error_msg;
}
}
}
아래 테이블을 만든 후 사용해 주세요 ^^;
create table visit (
uid int, auto_increment,
syear int,
smonth int,
sday int,
hit int
}
?><div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:12:10 PHP & HTML에서 이동 됨]</div>
//홈페이지 상단에 아래 부분만 붙이면 됩니다.
========== 시작 ============
include '/Visit.php';
session_start();
$visit = new Visit($dbconn);
$visit->listenVisit();
$visit_total = $visit->getVisit(); //전체 방문자
$visit_today = $visit->getVisit(date('Y'),date('n'),date('j')); //오늘방문자
unset($visit);
========== 끝 ============
아래는 클래스 파일입니다.
========================
- class.Visit.php
========================
/* 방문자 기록 관리 클래스 */
Class Visit
{
var $dbconn;
var $sql;
var $error_msg;
function Visit($dbconn){
$this->dbconn = $dbconn;
}
/*방문자 추출 메소드 */
function getVisit($syear='', $smonth='', $sday=''){
if($syear == '' && $smonth == '' && $sday == ''){
$this->sql = "select sum(hit) as hit from visit "; //총방문자 수
}
else {
$this->sql = "select hit from visit ";
if($syear != "")
$this->sql .= "where syear='$syear' ";
if($smonth != "")
$this->sql .= "and smonth='$smonth' ";
if($sday != "")
$this->sql .= "and sday='$sday' ";
}
$result = mysql_query($this->sql, $this->dbconn);
if($result){
if(mysql_num_rows($result))
return mysql_result($result,0,'hit');
else
return 0;
}
else {
$this->error_msg = mysql_error();
return 0;
}
}
function addVisit($syear, $smonth, $sday){
$this->sql = "insert into visit(syear, smonth, sday, hit)
values('$syear', '$smonth', '$sday', 1)";
$result = mysql_query($this->sql, $this->dbconn);
if($result)
return true;
else {
$this->error_msg = mysql_error();
return false;
}
}
function upVisit(){
$syear = date('Y');
$smonth = date('n');
$sday = date('j');
$is_data = $this->isVisit($syear, $smonth, $sday);
if($is_data)
$this->editVisit($syear, $smonth, $sday);
else
$this->addVisit($syear, $smonth, $sday);
}
function editVisit($syear, $smonth, $sday){
$this->sql = "update visit set hit=hit+1
where syear='$syear' and smonth='$smonth' and sday='$sday'";
$result = mysql_query($this->sql, $this->dbconn);
if($result)
return true;
else {
$this->error_msg = mysql_error();
return false;
}
}
function delVisit($uid){
$this->sql = "delete from visit where uid=$uid";
$result = mysql_query($this->sql, $this->dbconn);
if($result)
return true;
else {
$this->error_msg = mysql_error();
return false;
}
}
function isVisit($syear, $smonth, $sday){
$this->sql = "select uid from visit
where syear='$syear' and smonth='$smonth' and sday='$sday'";
$result = mysql_query($this->sql, $this->dbconn);
if($result){
if(mysql_num_rows($result))
return 1;
else
return 0;
}
else {
$this->error_msg = mysql_error();
return 1;
}
}
function listVisit($pageInfo, $syear='', $smonth='', $sday=''){
$this->sql = "select syear, smonth, sday, hit
from visit ";
if($syear != '') $this->sql .= " where syear='$syear'";
if($smonth != '') $this->sql .= " and smonth='$smonth'";
if($sday != '') $this->sql .= " and sday='$sday'";
$this->sql .= " order by syear desc, smonth desc, sday desc";
$result = mysql_query($this->sql, $this->dbconn);
if($result){
$j=0;
for($i=$pageInfo["first"]; $i<=$pageInfo["last"]; $i++){
$info["num"][$j] = $pageInfo["cnt"] - $i;
$info["syear"][$j] = mysql_result($result,$i,"syear");
$info["smonth"][$j] = mysql_result($result,$i,"smonth");
$info["sday"][$j] = mysql_result($result,$i,"sday");
$info["hit"][$j] = mysql_result($result,$i,"hit");
$j++;
}
return $info;
}
else {
$this->error_msg = mysql_error();
return false;
}
}
/* 20분 기준 방문자 체크 메소드 */
function listenVisit(){
$now_visit_date = mktime(date('H'),date('i'),0,date('m'),date('d'),date('Y'));
if($_COOKIE['visit_date'] != ''){
$old_visit_date = $_COOKIE['visit_date'];
$is_first = false;
}
else {
$old_visit_date = $now_visit_date;
setcookie('visit_date', $now_visit_date);
$is_first = true;
}
$diff_date = $now_visit_date - $old_visit_date;
if($diff_date > 1200 || $is_first == true){ //20분 응답 60 * 20
setcookie('visit_date', $now_visit_date);
$this->upVisit();
}
}
function getCnt($syear='', $smonth='', $sday=''){
$this->sql = "select count(uid) as cnt from visit";
if($syear != '') $this->sql .= " where syear='$syear'";
if($smonth != '') $this->sql .= " and smonth='$smonth'";
if($sday != '') $this->sql .= " and sday='$sday'";
$result = mysql_query($this->sql, $this->dbconn);
if($result){
$cnt = mysql_result($result,0,"cnt");
return $cnt;
}
else {
$this->error_msg = mysql_error();
return 0;
}
}
/* error를 출력하는 메소드 */
/* filter 0-error발생시 출력, 1-무조건 출력 */
function printErr($filter=0){
if($this->error_msg != '' || $filter == 1){
echo '<br>'.$this->sql;
echo '<br>'.$this->error_msg;
}
}
}
아래 테이블을 만든 후 사용해 주세요 ^^;
create table visit (
uid int, auto_increment,
syear int,
smonth int,
sday int,
hit int
}
?><div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:12:10 PHP & HTML에서 이동 됨]</div>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 8230 | 9년 전 | 119 | ||
| 8229 | 9년 전 | 117 | ||
| 8228 |
커네드커네드
|
9년 전 | 157 | |
| 8227 | 9년 전 | 201 | ||
| 8226 | 9년 전 | 214 | ||
| 8225 | 9년 전 | 196 | ||
| 8224 | 9년 전 | 189 | ||
| 8223 | 9년 전 | 168 | ||
| 8222 |
|
9년 전 | 244 | |
| 8221 | 9년 전 | 151 | ||
| 8220 | 9년 전 | 185 | ||
| 8219 | 9년 전 | 143 | ||
| 8218 | 9년 전 | 191 | ||
| 8217 |
star3840
|
9년 전 | 160 | |
| 8216 | 9년 전 | 230 | ||
| 8215 | 9년 전 | 180 | ||
| 8214 | 9년 전 | 279 | ||
| 8213 | 9년 전 | 229 | ||
| 8212 | 9년 전 | 144 | ||
| 8211 | 9년 전 | 317 | ||
| 8210 | 9년 전 | 326 | ||
| 8209 | 9년 전 | 397 | ||
| 8208 | 9년 전 | 287 | ||
| 8207 | 9년 전 | 290 | ||
| 8206 |
|
9년 전 | 245 | |
| 8205 | 9년 전 | 230 | ||
| 8204 | 9년 전 | 197 | ||
| 8203 | 9년 전 | 278 | ||
| 8202 | 9년 전 | 193 | ||
| 8201 | 9년 전 | 242 | ||
| 8200 | 9년 전 | 236 | ||
| 8199 | 9년 전 | 260 | ||
| 8198 | 9년 전 | 226 | ||
| 8197 | 9년 전 | 218 | ||
| 8196 | 9년 전 | 614 | ||
| 8195 | 9년 전 | 217 | ||
| 8194 | 9년 전 | 332 | ||
| 8193 | 9년 전 | 232 | ||
| 8192 | 9년 전 | 253 | ||
| 8191 | 9년 전 | 207 | ||
| 8190 | 9년 전 | 203 | ||
| 8189 | 9년 전 | 261 | ||
| 8188 | 9년 전 | 196 | ||
| 8187 | 9년 전 | 196 | ||
| 8186 | 9년 전 | 200 | ||
| 8185 | 9년 전 | 370 | ||
| 8184 | 9년 전 | 154 | ||
| 8183 | 9년 전 | 379 | ||
| 8182 | 9년 전 | 233 | ||
| 8181 | 9년 전 | 191 | ||
| 8180 | 9년 전 | 769 | ||
| 8179 | 9년 전 | 538 | ||
| 8178 | 9년 전 | 388 | ||
| 8177 |
kiplayer
|
9년 전 | 393 | |
| 8176 | 9년 전 | 422 | ||
| 8175 | 9년 전 | 301 | ||
| 8174 | 9년 전 | 303 | ||
| 8173 | 9년 전 | 396 | ||
| 8172 | 9년 전 | 261 | ||
| 8171 | 9년 전 | 234 | ||
| 8170 | 9년 전 | 357 | ||
| 8169 |
커네드커네드
|
9년 전 | 310 | |
| 8168 | 9년 전 | 380 | ||
| 8167 | 9년 전 | 375 | ||
| 8166 | 9년 전 | 282 | ||
| 8165 | 9년 전 | 225 | ||
| 8164 | 9년 전 | 363 | ||
| 8163 | 9년 전 | 352 | ||
| 8162 | 9년 전 | 359 | ||
| 8161 | 9년 전 | 372 | ||
| 8160 |
|
9년 전 | 565 | |
| 8159 | 9년 전 | 507 | ||
| 8158 | 9년 전 | 316 | ||
| 8157 | 9년 전 | 429 | ||
| 8156 | 9년 전 | 313 | ||
| 8155 | 9년 전 | 306 | ||
| 8154 |
00년생용띠
|
9년 전 | 647 | |
| 8153 | 9년 전 | 284 | ||
| 8152 |
|
9년 전 | 472 | |
| 8151 | 9년 전 | 466 | ||
| 8150 | 9년 전 | 574 | ||
| 8149 |
Jangfolk
|
9년 전 | 421 | |
| 8148 | 9년 전 | 239 | ||
| 8147 | 9년 전 | 440 | ||
| 8146 | 9년 전 | 515 | ||
| 8145 | 9년 전 | 467 | ||
| 8144 | 9년 전 | 428 | ||
| 8143 | 9년 전 | 261 | ||
| 8142 | 9년 전 | 485 | ||
| 8141 | 9년 전 | 432 | ||
| 8140 | 9년 전 | 981 | ||
| 8139 | 9년 전 | 333 | ||
| 8138 |
전갈자리남자
|
9년 전 | 440 | |
| 8137 | 9년 전 | 474 | ||
| 8136 | 9년 전 | 804 | ||
| 8135 |
|
9년 전 | 841 | |
| 8134 |
PlayPixel
|
9년 전 | 581 | |
| 8133 |
|
9년 전 | 496 | |
| 8132 | 9년 전 | 520 | ||
| 8131 | 9년 전 | 880 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기