간단한 사이트 작업일 경우
데이타 베이스를 사용하지 않고 현재 접속자를 출력하는 방법입니다.
아래의 예제는
현재 접속 경로와 리퍼러를 출력하는 예제입니다.
<?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
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 2230 | 16년 전 | 1293 | ||
| 2229 | 16년 전 | 2161 | ||
| 2228 | 16년 전 | 3226 | ||
| 2227 | 16년 전 | 2169 | ||
| 2226 | 16년 전 | 1755 | ||
| 2225 | 16년 전 | 1515 | ||
| 2224 |
|
16년 전 | 2046 | |
| 2223 | 16년 전 | 4730 | ||
| 2222 | 16년 전 | 1412 | ||
| 2221 |
|
16년 전 | 2146 | |
| 2220 |
|
16년 전 | 2137 | |
| 2219 |
|
16년 전 | 2407 | |
| 2218 |
|
16년 전 | 2149 | |
| 2217 |
|
16년 전 | 4440 | |
| 2216 |
|
16년 전 | 2928 | |
| 2215 | 16년 전 | 2868 | ||
| 2214 | 16년 전 | 1604 | ||
| 2213 | 16년 전 | 1252 | ||
| 2212 |
|
16년 전 | 3952 | |
| 2211 |
|
16년 전 | 1622 | |
| 2210 |
|
16년 전 | 1620 | |
| 2209 | 16년 전 | 2115 | ||
| 2208 | 16년 전 | 1887 | ||
| 2207 |
letsgolee
|
16년 전 | 1495 | |
| 2206 |
|
16년 전 | 3924 | |
| 2205 | 16년 전 | 1765 | ||
| 2204 | 16년 전 | 3136 | ||
| 2203 | 16년 전 | 3027 | ||
| 2202 | 16년 전 | 1048 | ||
| 2201 | 16년 전 | 1845 | ||
| 2200 | 16년 전 | 1598 | ||
| 2199 |
|
16년 전 | 1857 | |
| 2198 |
태양의서쪽
|
16년 전 | 2649 | |
| 2197 |
태양의서쪽
|
16년 전 | 3029 | |
| 2196 |
태양의서쪽
|
16년 전 | 3229 | |
| 2195 | 16년 전 | 3328 | ||
| 2194 | 16년 전 | 1470 | ||
| 2193 |
letsgolee
|
16년 전 | 1424 | |
| 2192 | 16년 전 | 2258 | ||
| 2191 | 17년 전 | 1977 | ||
| 2190 |
|
17년 전 | 2291 | |
| 2189 | 17년 전 | 2813 | ||
| 2188 |
Sizkein
|
17년 전 | 3261 | |
| 2187 |
letsgolee
|
17년 전 | 2360 | |
| 2186 |
Sizkein
|
17년 전 | 1637 | |
| 2185 |
Sizkein
|
17년 전 | 3208 | |
| 2184 |
Sizkein
|
17년 전 | 3064 | |
| 2183 | 17년 전 | 3042 | ||
| 2182 | 17년 전 | 3922 | ||
| 2181 | 17년 전 | 2588 | ||
| 2180 |
|
17년 전 | 2407 | |
| 2179 | 17년 전 | 2654 | ||
| 2178 | 17년 전 | 2899 | ||
| 2177 | 17년 전 | 2617 | ||
| 2176 | 17년 전 | 1454 | ||
| 2175 | 17년 전 | 1897 | ||
| 2174 | 17년 전 | 1496 | ||
| 2173 |
|
17년 전 | 1924 | |
| 2172 | 17년 전 | 2524 | ||
| 2171 | 17년 전 | 8709 | ||
| 2170 | 17년 전 | 3162 | ||
| 2169 | 17년 전 | 4251 | ||
| 2168 |
|
17년 전 | 1989 | |
| 2167 | 17년 전 | 3659 | ||
| 2166 |
|
17년 전 | 1554 | |
| 2165 | 17년 전 | 1388 | ||
| 2164 | 17년 전 | 2324 | ||
| 2163 | 17년 전 | 1319 | ||
| 2162 | 17년 전 | 1644 | ||
| 2161 | 17년 전 | 1460 | ||
| 2160 | 17년 전 | 2530 | ||
| 2159 |
inxps
|
17년 전 | 1503 | |
| 2158 |
inxps
|
17년 전 | 1098 | |
| 2157 | 17년 전 | 1231 | ||
| 2156 | 17년 전 | 3111 | ||
| 2155 | 17년 전 | 2178 | ||
| 2154 | 17년 전 | 1980 | ||
| 2153 |
|
17년 전 | 1224 | |
| 2152 |
letsgolee
|
17년 전 | 2455 | |
| 2151 | 17년 전 | 1172 | ||
| 2150 |
아름다운세상
|
17년 전 | 1130 | |
| 2149 |
아름다운세상
|
17년 전 | 1380 | |
| 2148 |
아름다운세상
|
17년 전 | 2739 | |
| 2147 |
|
17년 전 | 2399 | |
| 2146 | 17년 전 | 2487 | ||
| 2145 | 17년 전 | 1188 | ||
| 2144 | 17년 전 | 1307 | ||
| 2143 | 17년 전 | 3254 | ||
| 2142 | 17년 전 | 2839 | ||
| 2141 | 17년 전 | 4110 | ||
| 2140 | 17년 전 | 2260 | ||
| 2139 | 17년 전 | 2349 | ||
| 2138 | 17년 전 | 1402 | ||
| 2137 | 17년 전 | 2517 | ||
| 2136 | 17년 전 | 2202 | ||
| 2135 | 17년 전 | 2962 | ||
| 2134 |
아름다운세상
|
17년 전 | 2471 | |
| 2133 |
Juinjang
|
17년 전 | 1635 | |
| 2132 | 17년 전 | 2433 | ||
| 2131 | 17년 전 | 1591 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기