<?
//홈페이지 상단에 아래 부분만 붙이면 됩니다.
========== 시작 ============
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>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 1530 |
1111111
|
18년 전 | 1953 | |
| 1529 |
행복속네잎크로버
|
18년 전 | 3448 | |
| 1528 |
행복속네잎크로버
|
18년 전 | 1829 | |
| 1527 |
1111111
|
18년 전 | 7639 | |
| 1526 |
1111111
|
18년 전 | 3285 | |
| 1525 |
행복속네잎크로버
|
18년 전 | 1269 | |
| 1524 |
행복속네잎크로버
|
18년 전 | 2300 | |
| 1523 |
행복속네잎크로버
|
18년 전 | 3502 | |
| 1522 |
행복속네잎크로버
|
18년 전 | 2359 | |
| 1521 |
행복속네잎크로버
|
18년 전 | 2128 | |
| 1520 |
행복속네잎크로버
|
18년 전 | 2758 | |
| 1519 |
행복속네잎크로버
|
18년 전 | 3718 | |
| 1518 |
행복속네잎크로버
|
18년 전 | 3482 | |
| 1517 |
행복속네잎크로버
|
18년 전 | 2559 | |
| 1516 |
행복속네잎크로버
|
18년 전 | 1911 | |
| 1515 |
행복속네잎크로버
|
18년 전 | 1929 | |
| 1514 |
행복속네잎크로버
|
18년 전 | 2503 | |
| 1513 |
행복속네잎크로버
|
18년 전 | 1981 | |
| 1512 | 18년 전 | 2868 | ||
| 1511 | 18년 전 | 1659 | ||
| 1510 | 18년 전 | 2206 | ||
| 1509 | 18년 전 | 1679 | ||
| 1508 | 18년 전 | 2137 | ||
| 1507 | 18년 전 | 2356 | ||
| 1506 | 18년 전 | 2293 | ||
| 1505 | 18년 전 | 2245 | ||
| 1504 | 18년 전 | 2175 | ||
| 1503 | 18년 전 | 3483 | ||
| 1502 | 18년 전 | 1664 | ||
| 1501 | 18년 전 | 3440 | ||
| 1500 | 18년 전 | 2020 | ||
| 1499 | 18년 전 | 5291 | ||
| 1498 | 18년 전 | 2150 | ||
| 1497 |
hsp1980
|
18년 전 | 2330 | |
| 1496 |
hsp1980
|
18년 전 | 1723 | |
| 1495 |
hsp1980
|
18년 전 | 2132 | |
| 1494 |
hsp1980
|
18년 전 | 3644 | |
| 1493 | 18년 전 | 1499 | ||
| 1492 | 18년 전 | 1737 | ||
| 1491 | 18년 전 | 4317 | ||
| 1490 | 18년 전 | 3703 | ||
| 1489 | 18년 전 | 3263 | ||
| 1488 | 18년 전 | 3363 | ||
| 1487 |
mixdesign
|
18년 전 | 3863 | |
| 1486 |
mixdesign
|
18년 전 | 4323 | |
| 1485 | 18년 전 | 4246 | ||
| 1484 | 18년 전 | 2700 | ||
| 1483 |
hsp1980
|
18년 전 | 2309 | |
| 1482 |
hsp1980
|
18년 전 | 3245 | |
| 1481 |
hsp1980
|
18년 전 | 3162 | |
| 1480 |
hsp1980
|
18년 전 | 3317 | |
| 1479 | 18년 전 | 3255 | ||
| 1478 |
|
18년 전 | 4921 | |
| 1477 |
|
18년 전 | 5206 | |
| 1476 | 18년 전 | 3405 | ||
| 1475 |
mixdesign
|
18년 전 | 2716 | |
| 1474 |
mixdesign
|
18년 전 | 2939 | |
| 1473 |
mixdesign
|
18년 전 | 2266 | |
| 1472 |
mixdesign
|
18년 전 | 2084 | |
| 1471 |
mixdesign
|
18년 전 | 2034 | |
| 1470 |
|
18년 전 | 3072 | |
| 1469 |
mixdesign
|
18년 전 | 2353 | |
| 1468 |
mixdesign
|
18년 전 | 2371 | |
| 1467 |
mixdesign
|
18년 전 | 2049 | |
| 1466 |
mixdesign
|
18년 전 | 2419 | |
| 1465 |
mixdesign
|
18년 전 | 3151 | |
| 1464 | 18년 전 | 4081 | ||
| 1463 | 18년 전 | 3369 | ||
| 1462 |
|
18년 전 | 1998 | |
| 1461 |
|
18년 전 | 1940 | |
| 1460 | 18년 전 | 2857 | ||
| 1459 | 18년 전 | 1649 | ||
| 1458 |
|
18년 전 | 2000 | |
| 1457 |
mixdesign
|
18년 전 | 2292 | |
| 1456 |
mixdesign
|
18년 전 | 2156 | |
| 1455 | 18년 전 | 2263 | ||
| 1454 | 18년 전 | 4033 | ||
| 1453 | 18년 전 | 1773 | ||
| 1452 | 18년 전 | 4387 | ||
| 1451 | 18년 전 | 2919 | ||
| 1450 | 18년 전 | 2216 | ||
| 1449 | 18년 전 | 3267 | ||
| 1448 | 18년 전 | 2894 | ||
| 1447 | 18년 전 | 2823 | ||
| 1446 | 18년 전 | 5625 | ||
| 1445 | 18년 전 | 2291 | ||
| 1444 | 18년 전 | 3408 | ||
| 1443 |
|
18년 전 | 3321 | |
| 1442 | 18년 전 | 3707 | ||
| 1441 | 18년 전 | 3262 | ||
| 1440 | 18년 전 | 2437 | ||
| 1439 | 18년 전 | 2087 | ||
| 1438 | 18년 전 | 2540 | ||
| 1437 | 18년 전 | 6107 | ||
| 1436 | 18년 전 | 2732 | ||
| 1435 | 18년 전 | 4544 | ||
| 1434 | 18년 전 | 2041 | ||
| 1433 | 18년 전 | 10028 | ||
| 1432 | 18년 전 | 2475 | ||
| 1431 |
Psychedelico
|
18년 전 | 1538 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기