간단한 사이트 작업일 경우
데이타 베이스를 사용하지 않고 현재 접속자를 출력하는 방법입니다.
아래의 예제는
현재 접속 경로와 리퍼러를 출력하는 예제입니다.
<?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
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 1430 | 18년 전 | 2979 | ||
| 1429 | 18년 전 | 2923 | ||
| 1428 | 18년 전 | 2818 | ||
| 1427 | 18년 전 | 2130 | ||
| 1426 |
|
18년 전 | 2310 | |
| 1425 |
|
18년 전 | 2865 | |
| 1424 |
|
18년 전 | 2957 | |
| 1423 |
frotone
|
18년 전 | 4124 | |
| 1422 | 18년 전 | 6114 | ||
| 1421 | 18년 전 | 2048 | ||
| 1420 | 18년 전 | 2178 | ||
| 1419 | 18년 전 | 1887 | ||
| 1418 | 18년 전 | 1651 | ||
| 1417 | 18년 전 | 2632 | ||
| 1416 | 18년 전 | 1693 | ||
| 1415 | 18년 전 | 1560 | ||
| 1414 | 18년 전 | 4737 | ||
| 1413 | 18년 전 | 1787 | ||
| 1412 | 18년 전 | 1835 | ||
| 1411 | 18년 전 | 1844 | ||
| 1410 | 18년 전 | 1968 | ||
| 1409 | 18년 전 | 3626 | ||
| 1408 | 18년 전 | 1649 | ||
| 1407 | 18년 전 | 1519 | ||
| 1406 | 18년 전 | 1350 | ||
| 1405 | 18년 전 | 1853 | ||
| 1404 | 18년 전 | 1900 | ||
| 1403 |
frotone
|
18년 전 | 3645 | |
| 1402 | 18년 전 | 1975 | ||
| 1401 | 18년 전 | 3108 | ||
| 1400 | 18년 전 | 4727 | ||
| 1399 | 18년 전 | 2860 | ||
| 1398 | 18년 전 | 8045 | ||
| 1397 | 18년 전 | 4055 | ||
| 1396 |
|
18년 전 | 2738 | |
| 1395 | 18년 전 | 1520 | ||
| 1394 | 18년 전 | 2621 | ||
| 1393 | 18년 전 | 5036 | ||
| 1392 | 18년 전 | 5218 | ||
| 1391 |
cncafe
|
18년 전 | 2090 | |
| 1390 |
mixdesign
|
18년 전 | 4349 | |
| 1389 | 18년 전 | 4091 | ||
| 1388 |
mixdesign
|
18년 전 | 4141 | |
| 1387 | 18년 전 | 2261 | ||
| 1386 | 18년 전 | 4183 | ||
| 1385 |
mixdesign
|
18년 전 | 2170 | |
| 1384 | 18년 전 | 3277 | ||
| 1383 | 18년 전 | 4911 | ||
| 1382 | 18년 전 | 1946 | ||
| 1381 |
오디세우스
|
18년 전 | 3404 | |
| 1380 |
mixdesign
|
18년 전 | 1635 | |
| 1379 | 18년 전 | 2732 | ||
| 1378 |
mixdesign
|
18년 전 | 1660 | |
| 1377 | 18년 전 | 2707 | ||
| 1376 |
|
18년 전 | 2549 | |
| 1375 |
|
18년 전 | 1552 | |
| 1374 |
|
18년 전 | 1489 | |
| 1373 |
|
18년 전 | 1734 | |
| 1372 | 18년 전 | 2237 | ||
| 1371 | 18년 전 | 2014 | ||
| 1370 | 18년 전 | 2376 | ||
| 1369 | 18년 전 | 4913 | ||
| 1368 |
mixdesign
|
18년 전 | 1815 | |
| 1367 | 18년 전 | 1257 | ||
| 1366 | 18년 전 | 1376 | ||
| 1365 | 18년 전 | 1335 | ||
| 1364 | 18년 전 | 1078 | ||
| 1363 | 18년 전 | 1075 | ||
| 1362 | 18년 전 | 1406 | ||
| 1361 | 18년 전 | 1358 | ||
| 1360 | 18년 전 | 2346 | ||
| 1359 | 18년 전 | 1224 | ||
| 1358 | 18년 전 | 1607 | ||
| 1357 | 18년 전 | 2093 | ||
| 1356 | 18년 전 | 1273 | ||
| 1355 | 18년 전 | 2827 | ||
| 1354 | 18년 전 | 1270 | ||
| 1353 | 18년 전 | 1646 | ||
| 1352 | 18년 전 | 1497 | ||
| 1351 | 18년 전 | 1448 | ||
| 1350 | 18년 전 | 1234 | ||
| 1349 | 18년 전 | 1076 | ||
| 1348 | 18년 전 | 1664 | ||
| 1347 | 18년 전 | 1102 | ||
| 1346 | 18년 전 | 3614 | ||
| 1345 | 18년 전 | 1709 | ||
| 1344 |
mixdesign
|
18년 전 | 1789 | |
| 1343 | 18년 전 | 1115 | ||
| 1342 | 18년 전 | 1849 | ||
| 1341 | 18년 전 | 1094 | ||
| 1340 | 18년 전 | 1163 | ||
| 1339 | 18년 전 | 1014 | ||
| 1338 | 18년 전 | 1003 | ||
| 1337 | 18년 전 | 1095 | ||
| 1336 |
|
18년 전 | 2575 | |
| 1335 | 18년 전 | 1544 | ||
| 1334 | 18년 전 | 1636 | ||
| 1333 | 18년 전 | 1203 | ||
| 1332 | 18년 전 | 1872 | ||
| 1331 | 18년 전 | 1517 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기