간단한 사이트 작업일 경우
데이타 베이스를 사용하지 않고 현재 접속자를 출력하는 방법입니다.
아래의 예제는
현재 접속 경로와 리퍼러를 출력하는 예제입니다.
<?php
//현재 접속자 상세정보 가졍오기
//Yget_filelist_in_dir 함수에 의존성을 갖는다.
//Yread_file 함수에 의존성을 갖는다.
function Yin_user($dir_session){
$time1 = 60 * 10;//활동중인 현재 접속자 기준 1분
$time2 = 60 * 20;//현재접속자의 기준 5분
if (empty($dir_session)) return Array();
if (!is_dir($dir_session)) return Array();
$dir_array = Yget_filelist_in_dir($dir_session);
$return = Array();
$i = 1;
foreach($dir_array as $val){
if (filemtime($val) < (time() - $time2)) continue;
if (filemtime($val) > (time() - $time1)) {
$text = Yread_file($val);
$return[$i]['active'] = 'Active!!';
preg_match("`s_location\|s:.+:\"(.+)\";`U", $text, $m);
$m[1] = trim($m[1]);
$return[$i]['location'] = (!empty($m[1])) ? $m[1] : '위치정보 없음';
preg_match("`s_referer\|s:.+:\"(.+)\";`U", $text, $m);
$m[1] = trim($m[1]);
$return[$i]['referer'] = (!empty($m[1])) ? $m[1] : 'Direct!!';
}
else {
$text = Yread_file($val);
$return[$i]['active'] = 'Inactive!!';
preg_match("`s_location\|s:.+:\"(.+)\";`U", $text, $m);
$m[1] = trim($m[1]);
$return[$i]['location'] = (!empty($m[1])) ? $m[1] : '위치정보 없음';
preg_match("`s_referer\|s:.+:\"(.+)\";`U", $text, $m);
$m[1] = trim($m[1]);
$return[$i]['referer'] = (!empty($m[1])) ? $m[1] : 'Direct!!';
}
$i++;
}
return $return;
}
//넘어온 디렉토리의 모든 일차 파일리스트를 배열로 반환
function Yget_filelist_in_dir($dir_path){
$dir_path = preg_replace("`/+$`", '', $dir_path);
if(!is_dir($dir_path)) return Array();
$return_file = Array();
$d = dir($dir_path) or die('해당 디렉토리(' . $dir_path . ')를 열수 없습니다.');
while (false !== ($entry = $d->read())) {
$temp_file = $dir_path . '/' . $entry;
if (is_file($temp_file) && !preg_match("`\.$`", $temp_file)) {
$return_file[] = $temp_file;
}
}
$d->close();
return $return_file;
}
//로컬파일 읽어오기
function Yread_file ($read_file_path){
if (empty($read_file_path) || !file_exists($read_file_path)) return false;
if (is_readable($read_file_path) !== true) die('해당 파일(' . $read_file_path . ')은 읽을 권한이 없는 파일입니다.');
$fr = fopen($read_file_path, "r") or die('해당 파일(' . $read_file_path . ')을 열수 없습니다.');
if (empty($fr)) return false;
$filesize = filesize($read_file_path);
if (empty($filesize)) $filesize = 1024;
$read_text = fread($fr, $filesize);
fclose($fr);
if (empty($read_text)) return false;
return $read_text;
}
//각 페이지 접속시 세션 시작 이후 페이지 로케이션을 세션으로 저장한 경우 사용할수 있습니다.
//저같은 경우
if (empty($title)) $location = $_SERVER['PHP_SELF'];
else $location = $title;
$_SESSION['s_location'] = $location;
if (!empty($_SERVER['HTTP_REFERER']) && !preg_match("`^https?://(www\.)?chancein\.com`i", $_SERVER['HTTP_REFERER'])) $_SESSION['s_referer'] = $_SERVER['HTTP_REFERER'];
unset($location);
//현재 접속자 가져오기, 세션을 저장하는 디렉토리 경로를 절대경로 or 상대경로로서 인자로 넘김, $dir_data_session
//출력
$current = Yin_user($dir_data_session);
foreach($current as $k =>$v){
echo '<b>' . $k . '.</b> [<b>' . $v['active'] . '</b>] ' . $v['location'] . '<br> [<b>referer</b>] ' . $v['referer'] . '<br><br>';
}
?>
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7830 | 9년 전 | 374 | ||
| 7829 |
|
9년 전 | 551 | |
| 7828 | 9년 전 | 484 | ||
| 7827 | 9년 전 | 371 | ||
| 7826 | 9년 전 | 378 | ||
| 7825 | 9년 전 | 432 | ||
| 7824 | 9년 전 | 416 | ||
| 7823 | 9년 전 | 319 | ||
| 7822 | 9년 전 | 315 | ||
| 7821 | 9년 전 | 261 | ||
| 7820 | 9년 전 | 315 | ||
| 7819 |
|
9년 전 | 716 | |
| 7818 | 10년 전 | 335 | ||
| 7817 | 10년 전 | 450 | ||
| 7816 | 10년 전 | 354 | ||
| 7815 | 10년 전 | 557 | ||
| 7814 | 10년 전 | 381 | ||
| 7813 | 10년 전 | 318 | ||
| 7812 | 10년 전 | 343 | ||
| 7811 | 10년 전 | 361 | ||
| 7810 | 10년 전 | 489 | ||
| 7809 | 10년 전 | 430 | ||
| 7808 | 10년 전 | 288 | ||
| 7807 | 10년 전 | 352 | ||
| 7806 |
프로그래머7
|
10년 전 | 1305 | |
| 7805 | 10년 전 | 1217 | ||
| 7804 |
zahir1312
|
10년 전 | 741 | |
| 7803 |
|
10년 전 | 1343 | |
| 7802 | 10년 전 | 398 | ||
| 7801 | 10년 전 | 826 | ||
| 7800 | 10년 전 | 1043 | ||
| 7799 | 10년 전 | 499 | ||
| 7798 | 10년 전 | 447 | ||
| 7797 | 10년 전 | 448 | ||
| 7796 | 10년 전 | 300 | ||
| 7795 | 10년 전 | 451 | ||
| 7794 | 10년 전 | 477 | ||
| 7793 | 10년 전 | 994 | ||
| 7792 | 10년 전 | 401 | ||
| 7791 | 10년 전 | 486 | ||
| 7790 | 10년 전 | 453 | ||
| 7789 |
fbastore
|
10년 전 | 1398 | |
| 7788 | 10년 전 | 484 | ||
| 7787 | 10년 전 | 348 | ||
| 7786 | 10년 전 | 500 | ||
| 7785 | 10년 전 | 519 | ||
| 7784 | 10년 전 | 586 | ||
| 7783 | 10년 전 | 389 | ||
| 7782 | 10년 전 | 444 | ||
| 7781 | 10년 전 | 844 | ||
| 7780 | 10년 전 | 775 | ||
| 7779 | 10년 전 | 746 | ||
| 7778 | 10년 전 | 315 | ||
| 7777 | 10년 전 | 394 | ||
| 7776 | 10년 전 | 401 | ||
| 7775 | 10년 전 | 337 | ||
| 7774 | 10년 전 | 599 | ||
| 7773 | 10년 전 | 320 | ||
| 7772 | 10년 전 | 661 | ||
| 7771 | 10년 전 | 326 | ||
| 7770 | 10년 전 | 609 | ||
| 7769 | 10년 전 | 327 | ||
| 7768 | 10년 전 | 546 | ||
| 7767 | 10년 전 | 1115 | ||
| 7766 | 10년 전 | 442 | ||
| 7765 | 10년 전 | 471 | ||
| 7764 |
잘살아보자
|
10년 전 | 324 | |
| 7763 |
|
10년 전 | 1398 | |
| 7762 |
Tosea
|
10년 전 | 1017 | |
| 7761 | 10년 전 | 611 | ||
| 7760 |
잘살아보자
|
10년 전 | 597 | |
| 7759 |
잘살아보자
|
10년 전 | 408 | |
| 7758 |
잘살아보자
|
10년 전 | 528 | |
| 7757 | 10년 전 | 1176 | ||
| 7756 |
ITBANK
|
10년 전 | 1216 | |
| 7755 | 10년 전 | 1893 | ||
| 7754 | 10년 전 | 994 | ||
| 7753 | 10년 전 | 840 | ||
| 7752 | 10년 전 | 1344 | ||
| 7751 |
잘살아보자
|
10년 전 | 469 | |
| 7750 |
잘살아보자
|
10년 전 | 436 | |
| 7749 |
잘살아보자
|
10년 전 | 434 | |
| 7748 |
잘살아보자
|
10년 전 | 418 | |
| 7747 |
잘살아보자
|
10년 전 | 506 | |
| 7746 |
잘살아보자
|
10년 전 | 624 | |
| 7745 |
잘살아보자
|
10년 전 | 868 | |
| 7744 |
잘살아보자
|
10년 전 | 386 | |
| 7743 | 10년 전 | 912 | ||
| 7742 |
starbros
|
10년 전 | 784 | |
| 7741 |
잘살아보자
|
10년 전 | 599 | |
| 7740 |
잘살아보자
|
10년 전 | 474 | |
| 7739 |
잘살아보자
|
10년 전 | 431 | |
| 7738 |
잘살아보자
|
10년 전 | 485 | |
| 7737 |
잘살아보자
|
10년 전 | 442 | |
| 7736 |
잘살아보자
|
10년 전 | 466 | |
| 7735 |
잘살아보자
|
10년 전 | 800 | |
| 7734 |
잘살아보자
|
10년 전 | 391 | |
| 7733 |
잘살아보자
|
10년 전 | 490 | |
| 7732 |
잘살아보자
|
10년 전 | 647 | |
| 7731 |
잘살아보자
|
10년 전 | 573 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기