<?
//홈페이지 상단에 아래 부분만 붙이면 됩니다.
========== 시작 ============
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>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 1730 | 17년 전 | 1179 | ||
| 1729 | 17년 전 | 1607 | ||
| 1728 | 17년 전 | 1673 | ||
| 1727 | 17년 전 | 1813 | ||
| 1726 | 17년 전 | 2951 | ||
| 1725 | 17년 전 | 2089 | ||
| 1724 |
|
17년 전 | 1767 | |
| 1723 |
끝없는사랑
|
17년 전 | 2108 | |
| 1722 |
끝없는사랑
|
17년 전 | 1814 | |
| 1721 | 17년 전 | 3345 | ||
| 1720 | 17년 전 | 1529 | ||
| 1719 | 17년 전 | 1646 | ||
| 1718 |
사랑합니다
|
17년 전 | 1364 | |
| 1717 | 17년 전 | 2184 | ||
| 1716 | 17년 전 | 3138 | ||
| 1715 |
|
17년 전 | 2271 | |
| 1714 |
|
17년 전 | 1730 | |
| 1713 | 17년 전 | 2986 | ||
| 1712 | 17년 전 | 4421 | ||
| 1711 | 17년 전 | 1735 | ||
| 1710 | 17년 전 | 3238 | ||
| 1709 |
jeans
|
17년 전 | 1565 | |
| 1708 |
|
17년 전 | 3474 | |
| 1707 | 17년 전 | 5839 | ||
| 1706 |
|
17년 전 | 1419 | |
| 1705 |
|
17년 전 | 2156 | |
| 1704 | 17년 전 | 1787 | ||
| 1703 |
심심맨닷컴
|
17년 전 | 1546 | |
| 1702 | 17년 전 | 2418 | ||
| 1701 |
|
17년 전 | 2619 | |
| 1700 | 17년 전 | 1599 | ||
| 1699 | 17년 전 | 2682 | ||
| 1698 |
RedRiverFisher
|
17년 전 | 3166 | |
| 1697 |
심심맨닷컴
|
17년 전 | 1527 | |
| 1696 |
eclub
|
17년 전 | 1936 | |
| 1695 | 17년 전 | 3841 | ||
| 1694 |
깜장고무신
|
17년 전 | 4474 | |
| 1693 |
stuartkim
|
17년 전 | 1879 | |
| 1692 |
stuartkim
|
17년 전 | 1742 | |
| 1691 |
|
17년 전 | 2668 | |
| 1690 | 17년 전 | 1843 | ||
| 1689 | 17년 전 | 3930 | ||
| 1688 | 17년 전 | 1653 | ||
| 1687 | 16년 전 | 1924 | ||
| 1686 |
|
17년 전 | 2254 | |
| 1685 | 17년 전 | 2103 | ||
| 1684 |
|
17년 전 | 3568 | |
| 1683 |
leeLook
|
17년 전 | 1588 | |
| 1682 | 17년 전 | 2652 | ||
| 1681 | 17년 전 | 1641 | ||
| 1680 | 17년 전 | 1902 | ||
| 1679 | 17년 전 | 7418 | ||
| 1678 | 17년 전 | 1994 | ||
| 1677 | 17년 전 | 4090 | ||
| 1676 | 17년 전 | 2415 | ||
| 1675 | 17년 전 | 2424 | ||
| 1674 | 17년 전 | 2149 | ||
| 1673 | 17년 전 | 2197 | ||
| 1672 | 17년 전 | 2622 | ||
| 1671 | 17년 전 | 3215 | ||
| 1670 | 17년 전 | 5324 | ||
| 1669 |
플래시007
|
17년 전 | 2780 | |
| 1668 |
|
17년 전 | 2696 | |
| 1667 | 17년 전 | 2549 | ||
| 1666 |
|
17년 전 | 1795 | |
| 1665 | 17년 전 | 2203 | ||
| 1664 | 17년 전 | 5306 | ||
| 1663 |
|
17년 전 | 3019 | |
| 1662 |
|
17년 전 | 2579 | |
| 1661 |
|
17년 전 | 3254 | |
| 1660 |
|
17년 전 | 2467 | |
| 1659 |
|
17년 전 | 2827 | |
| 1658 | 17년 전 | 5873 | ||
| 1657 | 17년 전 | 2630 | ||
| 1656 |
Piece
|
17년 전 | 2017 | |
| 1655 |
|
17년 전 | 2651 | |
| 1654 | 17년 전 | 1474 | ||
| 1653 | 17년 전 | 9796 | ||
| 1652 | 17년 전 | 4454 | ||
| 1651 | 17년 전 | 3285 | ||
| 1650 | 17년 전 | 1811 | ||
| 1649 | 17년 전 | 3599 | ||
| 1648 | 17년 전 | 2284 | ||
| 1647 | 17년 전 | 3731 | ||
| 1646 | 17년 전 | 5183 | ||
| 1645 | 17년 전 | 3846 | ||
| 1644 | 17년 전 | 2695 | ||
| 1643 | 17년 전 | 2940 | ||
| 1642 | 17년 전 | 2447 | ||
| 1641 | 17년 전 | 2786 | ||
| 1640 |
porgy
|
17년 전 | 1897 | |
| 1639 | 18년 전 | 3442 | ||
| 1638 |
컴퓨터기술자
|
18년 전 | 2134 | |
| 1637 |
|
18년 전 | 2258 | |
| 1636 | 18년 전 | 2072 | ||
| 1635 | 18년 전 | 3047 | ||
| 1634 |
귀여운현호
|
18년 전 | 1995 | |
| 1633 |
태양의서쪽
|
18년 전 | 2669 | |
| 1632 | 18년 전 | 3868 | ||
| 1631 | 18년 전 | 4566 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기