간단한 사이트 작업일 경우
데이타 베이스를 사용하지 않고 현재 접속자를 출력하는 방법입니다.
아래의 예제는
현재 접속 경로와 리퍼러를 출력하는 예제입니다.
<?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
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 1230 |
|
18년 전 | 2013 | |
| 1229 |
|
18년 전 | 2948 | |
| 1228 |
|
18년 전 | 2635 | |
| 1227 | 18년 전 | 2933 | ||
| 1226 | 18년 전 | 2365 | ||
| 1225 |
|
18년 전 | 2436 | |
| 1224 | 18년 전 | 2747 | ||
| 1223 |
|
18년 전 | 3995 | |
| 1222 |
mixdesign
|
18년 전 | 2638 | |
| 1221 |
|
18년 전 | 2755 | |
| 1220 | 18년 전 | 3210 | ||
| 1219 | 18년 전 | 2919 | ||
| 1218 | 18년 전 | 2114 | ||
| 1217 |
|
18년 전 | 2560 | |
| 1216 | 18년 전 | 2580 | ||
| 1215 |
mixdesign
|
18년 전 | 4061 | |
| 1214 |
|
18년 전 | 4790 | |
| 1213 | 18년 전 | 2326 | ||
| 1212 |
mixdesign
|
18년 전 | 2504 | |
| 1211 |
|
18년 전 | 2430 | |
| 1210 | 18년 전 | 3758 | ||
| 1209 |
mixdesign
|
18년 전 | 2378 | |
| 1208 |
mixdesign
|
18년 전 | 2380 | |
| 1207 |
mixdesign
|
18년 전 | 1730 | |
| 1206 |
mixdesign
|
18년 전 | 2008 | |
| 1205 |
mixdesign
|
18년 전 | 2705 | |
| 1204 |
mixdesign
|
18년 전 | 3582 | |
| 1203 | 18년 전 | 3097 | ||
| 1202 | 18년 전 | 2982 | ||
| 1201 | 18년 전 | 2036 | ||
| 1200 | 18년 전 | 4133 | ||
| 1199 | 18년 전 | 2175 | ||
| 1198 | 18년 전 | 4198 | ||
| 1197 | 18년 전 | 2511 | ||
| 1196 | 18년 전 | 2369 | ||
| 1195 |
|
18년 전 | 3471 | |
| 1194 | 18년 전 | 2244 | ||
| 1193 | 18년 전 | 2157 | ||
| 1192 | 18년 전 | 3276 | ||
| 1191 | 18년 전 | 3965 | ||
| 1190 | 18년 전 | 2228 | ||
| 1189 |
|
18년 전 | 2365 | |
| 1188 |
|
18년 전 | 3835 | |
| 1187 | 18년 전 | 2713 | ||
| 1186 | 18년 전 | 3380 | ||
| 1185 | 18년 전 | 2787 | ||
| 1184 | 18년 전 | 1668 | ||
| 1183 | 18년 전 | 2140 | ||
| 1182 | 18년 전 | 3707 | ||
| 1181 |
mermaid
|
18년 전 | 2923 | |
| 1180 | 18년 전 | 2985 | ||
| 1179 | 18년 전 | 3611 | ||
| 1178 | 18년 전 | 2178 | ||
| 1177 |
|
18년 전 | 2291 | |
| 1176 | 18년 전 | 3180 | ||
| 1175 | 18년 전 | 1880 | ||
| 1174 |
|
18년 전 | 2237 | |
| 1173 |
|
18년 전 | 2529 | |
| 1172 | 18년 전 | 1777 | ||
| 1171 | 18년 전 | 2110 | ||
| 1170 | 18년 전 | 1993 | ||
| 1169 | 18년 전 | 2508 | ||
| 1168 | 18년 전 | 1932 | ||
| 1167 | 18년 전 | 1727 | ||
| 1166 | 18년 전 | 1754 | ||
| 1165 | 18년 전 | 1732 | ||
| 1164 | 18년 전 | 2798 | ||
| 1163 | 18년 전 | 1561 | ||
| 1162 |
|
18년 전 | 5680 | |
| 1161 |
이걸~어쩌나~
|
18년 전 | 2412 | |
| 1160 | 18년 전 | 1673 | ||
| 1159 | 18년 전 | 4704 | ||
| 1158 | 18년 전 | 2056 | ||
| 1157 | 18년 전 | 4844 | ||
| 1156 | 18년 전 | 3195 | ||
| 1155 | 18년 전 | 2137 | ||
| 1154 | 18년 전 | 1833 | ||
| 1153 |
BEST79
|
18년 전 | 2114 | |
| 1152 | 18년 전 | 1730 | ||
| 1151 | 18년 전 | 1847 | ||
| 1150 | 18년 전 | 1852 | ||
| 1149 |
inniskun
|
18년 전 | 2484 | |
| 1148 |
|
18년 전 | 3502 | |
| 1147 |
|
18년 전 | 5980 | |
| 1146 |
|
18년 전 | 3868 | |
| 1145 | 18년 전 | 3062 | ||
| 1144 | 18년 전 | 2141 | ||
| 1143 | 18년 전 | 2418 | ||
| 1142 | 18년 전 | 2205 | ||
| 1141 |
|
18년 전 | 2308 | |
| 1140 | 18년 전 | 2418 | ||
| 1139 | 18년 전 | 2848 | ||
| 1138 | 18년 전 | 2542 | ||
| 1137 | 18년 전 | 2004 | ||
| 1136 | 18년 전 | 3134 | ||
| 1135 | 18년 전 | 3598 | ||
| 1134 | 18년 전 | 3841 | ||
| 1133 |
자반고등어
|
18년 전 | 3348 | |
| 1132 | 18년 전 | 3395 | ||
| 1131 | 18년 전 | 2579 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기