<?
//홈페이지 상단에 아래 부분만 붙이면 됩니다.
========== 시작 ============
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>
게시글 목록
| 번호 | 제목 |
|---|---|
| 10331 | |
| 28724 |
HTML
싸이월드 둥근 테두리 만드는 방법
2
|
| 10329 | |
| 10328 | |
| 10326 |
JavaScript
히스토리 브러시 툴(History Brush Tool, 단축키 - Y)
1
|
| 10324 | |
| 10323 | |
| 28723 | |
| 10322 |
JavaScript
슬라이스 툴- Slice Tool (단축키 K)
|
| 10321 | |
| 10320 | |
| 28722 | |
| 10318 | |
| 28719 |
HTML
포토샵 레이어의 이해
2
|
| 10317 |
JavaScript
포토샵 해상도의 종류
|
| 10314 | |
| 10312 | |
| 28716 |
HTML
점선 그리는 법...
2
|
| 10308 |
Flash
포토샵에서 쓰이는 파일정보 입니다.
3
|
| 10307 |
JavaScript
♣ 영문으로 보이는 한글폰트를 한글명으로
|
| 10306 | |
| 10305 | |
| 28715 |
HTML
일러스트 단축키2
|
| 10304 |
JavaScript
일러스트 단축키
|
| 10303 | |
| 28714 | |
| 10302 |
Flash
자동으로 창크기 변환
|
| 28713 |
HTML
XP서비스팩2 무시하고 새창 띄우기
|
| 10301 |
MySQL
mysql table 유뮤 확인 코딩[펌]
|
| 10300 |
PHP
php환경 변수 출력
|
| 10299 | |
| 10296 |
기타
연합뉴스 뉴스티커
2
|
| 10294 | |
| 10293 | |
| 10292 | |
| 10291 |
JavaScript
ls 명령에서 LS_COLOR 환경변수로 확장자별 색 바꾸기
|
| 10289 |
JavaScript
php 날짜, 시간 함수 관련 팁
1
|
| 10285 |
PHP
PHP팁 (보안 등)
3
|
| 28711 |
HTML
개행문자 없애기[펌]
1
|
| 10281 |
Flash
swf 바탕빼서 적용하기
3
|
| 10279 |
Flash
mp3 play 플래시 소스입돠~
1
|
| 28710 | |
| 10278 | |
| 10277 | |
| 10276 | |
| 28709 | |
| 10273 | |
| 10270 |
JavaScript
돌맹이로 글자쓰기 ㅡㅡ;; 강좌...
2
|
| 10269 |
JavaScript
주소 보여주기 시를 때 제가 자주 쓰는 방법 이건 조회수 빵이다 ㅡ0ㅡ;
|
| 10267 | |
| 28708 | |
| 10266 | |
| 10264 | |
| 10263 |
JavaScript
마우스 오버시에 텍스트 버튼느낌 style.css 와 자동 스크롤 기능
|
| 10261 | |
| 28707 |
HTML
웹 폰트 적용 시키기 - 초보자용 -
|
| 10260 |
JavaScript
접속때마다 음악 다르게 나오기
|
| 10256 |
JavaScript
img 태그에 border=0을 넣지 않고 적용
3
|
| 10255 | |
| 28706 |
HTML
페이지 자동 이동 방법 3가지!!!
|
| 10253 | |
| 28704 |
HTML
body옆의 스크롤바흔적없애기
1
|
| 10250 |
기타
소스훔쳐보기
2
|
| 28703 |
HTML
마우스 오른쪽 버튼 사용금지
|
| 28702 |
HTML
마우스 룰오버시 여러가지 효과내기
|
| 10249 |
Flash
스위시 무비를 플래시에서 들여오기할 때
|
| 10247 |
Flash
SWF 파일 용량 줄이기
1
|
| 10245 | |
| 10243 | |
| 10240 |
Flash
4. 자주 쓰는 플래시 액션스크립트 용어
2
|
| 10239 | |
| 10238 |
Flash
2. 무비 크기를 줄이기 위한 10가지 방법
|
| 10237 |
Flash
1. 메뉴보다 빠른 단축키(Hot Key)들
|
| 10235 |
Flash
여러가지팁
1
|
| 10225 | |
| 28700 |
HTML
포토샾 팁 72가지
1
|
| 10213 | |
| 10210 | |
| 10207 | |
| 10205 | |
| 10204 | |
| 28693 | |
| 10198 |
Flash
실시간채팅창 붙이기 플래시 버튼액션..
5
|
| 10195 |
JavaScript
php폼메일로 일본어 메일 보내기
2
|
| 10191 |
JavaScript
원하는 부분만 프린트하기.
3
|
| 24785 | |
| 28674 |
HTML
디렉토리 이미지 뷰어
18
|
| 24784 | |
| 10189 | |
| 10187 | |
| 10182 | |
| 28669 | |
| 10181 | |
| 10175 | |
| 24779 | |
| 24772 | |
| 10173 | |
| 10168 |
JavaScript
웹호스팅서버 보안 - Open DNS 막기
4
|
| 10163 | |
| 10160 |
JavaScript
자동 스크롤 메뉴 (끄기 기능)
2
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기