간단한 사이트 작업일 경우
데이타 베이스를 사용하지 않고 현재 접속자를 출력하는 방법입니다.
아래의 예제는
현재 접속 경로와 리퍼러를 출력하는 예제입니다.
<?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>';
}
?>
예제 : http://chancein.com/svc/current.php
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 2130 | 17년 전 | 1178 | ||
| 2129 |
ⓧ힘내세요
|
17년 전 | 2234 | |
| 2128 | 17년 전 | 2872 | ||
| 2127 | 17년 전 | 4056 | ||
| 2126 | 17년 전 | 3144 | ||
| 2125 | 17년 전 | 1407 | ||
| 2124 | 17년 전 | 1707 | ||
| 2123 | 17년 전 | 2237 | ||
| 2122 | 17년 전 | 1544 | ||
| 2121 | 17년 전 | 1719 | ||
| 2120 | 17년 전 | 2718 | ||
| 2119 | 17년 전 | 2143 | ||
| 2118 | 17년 전 | 1797 | ||
| 2117 |
아름다운세상
|
17년 전 | 4205 | |
| 2116 | 17년 전 | 3049 | ||
| 2115 | 17년 전 | 1435 | ||
| 2114 |
아름다운세상
|
17년 전 | 3569 | |
| 2113 | 17년 전 | 2794 | ||
| 2112 | 17년 전 | 2074 | ||
| 2111 | 17년 전 | 1290 | ||
| 2110 | 17년 전 | 2329 | ||
| 2109 | 17년 전 | 2065 | ||
| 2108 | 17년 전 | 1983 | ||
| 2107 |
휴전합시다
|
17년 전 | 1919 | |
| 2106 | 17년 전 | 1168 | ||
| 2105 |
|
17년 전 | 1871 | |
| 2104 | 17년 전 | 2925 | ||
| 2103 | 17년 전 | 1427 | ||
| 2102 | 17년 전 | 1670 | ||
| 2101 | 17년 전 | 1354 | ||
| 2100 | 17년 전 | 1598 | ||
| 2099 | 17년 전 | 1574 | ||
| 2098 | 17년 전 | 1445 | ||
| 2097 | 17년 전 | 2556 | ||
| 2096 | 17년 전 | 2325 | ||
| 2095 | 17년 전 | 2109 | ||
| 2094 | 17년 전 | 1421 | ||
| 2093 | 17년 전 | 2430 | ||
| 2092 | 17년 전 | 4262 | ||
| 2091 | 17년 전 | 2748 | ||
| 2090 | 17년 전 | 1664 | ||
| 2089 | 17년 전 | 1856 | ||
| 2088 | 17년 전 | 3236 | ||
| 2087 | 17년 전 | 2234 | ||
| 2086 | 17년 전 | 3830 | ||
| 2085 | 17년 전 | 1679 | ||
| 2084 | 17년 전 | 2280 | ||
| 2083 | 17년 전 | 2101 | ||
| 2082 | 17년 전 | 1613 | ||
| 2081 | 17년 전 | 2128 | ||
| 2080 |
letsgolee
|
17년 전 | 1921 | |
| 2079 | 17년 전 | 1961 | ||
| 2078 | 17년 전 | 3071 | ||
| 2077 | 17년 전 | 2144 | ||
| 2076 | 17년 전 | 1439 | ||
| 2075 | 17년 전 | 1458 | ||
| 2074 | 17년 전 | 2127 | ||
| 2073 | 17년 전 | 3206 | ||
| 2072 | 17년 전 | 2136 | ||
| 2071 |
휴전합시다
|
17년 전 | 1532 | |
| 2070 | 17년 전 | 4242 | ||
| 2069 | 17년 전 | 2038 | ||
| 2068 | 17년 전 | 3460 | ||
| 2067 | 17년 전 | 6033 | ||
| 2066 | 17년 전 | 1483 | ||
| 2065 |
letsgolee
|
17년 전 | 1653 | |
| 2064 | 17년 전 | 1235 | ||
| 2063 | 17년 전 | 1347 | ||
| 2062 |
vicky
|
17년 전 | 2873 | |
| 2061 | 17년 전 | 1909 | ||
| 2060 |
카프카07
|
17년 전 | 2594 | |
| 2059 | 17년 전 | 1308 | ||
| 2058 | 17년 전 | 3184 | ||
| 2057 | 17년 전 | 2164 | ||
| 2056 | 17년 전 | 2611 | ||
| 2055 | 17년 전 | 1405 | ||
| 2054 | 17년 전 | 1752 | ||
| 2053 | 17년 전 | 1145 | ||
| 2052 |
|
17년 전 | 1203 | |
| 2051 | 17년 전 | 1788 | ||
| 2050 | 17년 전 | 1229 | ||
| 2049 | 17년 전 | 4313 | ||
| 2048 | 17년 전 | 1512 | ||
| 2047 | 17년 전 | 2009 | ||
| 2046 |
카프카07
|
17년 전 | 7091 | |
| 2045 | 17년 전 | 1384 | ||
| 2044 | 17년 전 | 1904 | ||
| 2043 | 17년 전 | 3133 | ||
| 2042 | 17년 전 | 1225 | ||
| 2041 |
카프카07
|
17년 전 | 1986 | |
| 2040 | 17년 전 | 1156 | ||
| 2039 |
smilesol
|
17년 전 | 1849 | |
| 2038 | 17년 전 | 2154 | ||
| 2037 |
|
17년 전 | 2969 | |
| 2036 | 17년 전 | 1247 | ||
| 2035 |
|
17년 전 | 1338 | |
| 2034 |
ㅣ곰탱이ㅣ
|
17년 전 | 1563 | |
| 2033 |
|
17년 전 | 1232 | |
| 2032 | 17년 전 | 4355 | ||
| 2031 | 17년 전 | 3899 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기