data/session 파일중 오래된 것들 삭제하기

· 2018-02-03 (토) 12:43:07 · 6529 · 1

세션파일이 보통은 삭제되지만 서버 설정에 따라 오랫동안 삭제안되는경우도 있습니다.

서버를 운영하시는 분은 다음 파일을 php 로 실행하거나

웹호스팅하면 자기 폴더만 지정하시면 되겠네요.

 

<?php
/* 작성 : howcode.co.kr 김성대 2018-02-03 */
/* 마음대로 퍼가도 됩니다. */
set_time_limit(0);
ini_set('max_execution_time', 300000); 
ini_set('mysql.connect_timeout', 90000);
ini_set('mysql.connect_timeout', 90000);
date_default_timezone_set('Asia/Seoul');
if (!isset($config)) $config=array();
$config['show']=false;
//$config['show']=true;

ar_check_dir("/home");
ar_check_dir("/home2");

function ar_check_dir($path) {
        global $config;
        $handle = @opendir($path);
        if (!$handle) return;
        //if ($config['show']) echo "path:({$config['ar_count_path']}) $path\n";
        if (strstr($path,'/data/session')) {
            if ($config['show']) echo "$path\n";
        }

        while ($file = readdir($handle))
        {
                $filename=$path.'/'.$file;
                if($file == "."||$file == "..") continue;
                if (is_dir($filename)) {
                        ar_check_dir($filename);
                }
                else if (strstr($path,'/data/session')&&strstr($file,'sess_')) {
                        ar_check_file($filename);
                }
        }
        closedir($handle);
}


function ar_check_file($filename) {
    global $config;
    if (strstr($filename,'.php')) {
            echo "ERROR : in .php $filename\n";
            return;
    }
    if (!strstr($filename,'sess_')) return;
    $t=filemtime($filename);
    if ($t<time()-24*3600) {
            if ($config['show']) echo "delete $filename ",date("Y-m-d H:i:s",$t),"\n";
            @unlink($filename);
    }
}
 

첨부파일

ar_delete_session.php (1.5 KB) 28회 2018-02-03 12:43
|

댓글 1개

호스팅 사용중 인데요
1ㅡ어디에 어떻게 지정 하라는 건지요 ??
2ㅡ그리고 첨부된 파일을 계정 어느위치치에 올려야 하는지요 ?
댓글을 작성하시려면 로그인이 필요합니다.

그누보드5 팁자료실

2,788건
+
제목 글쓴이 날짜 조회
18-02-24 조회 7,631
18-02-23 조회 6,458
18-02-23 조회 8,560
18-02-22 조회 5,475
18-02-22 조회 6,558
18-02-21 조회 6,955
18-02-21 조회 6,062
18-02-20 조회 5,274
18-02-20 조회 6,602
18-02-19 조회 7,324
18-02-19 조회 2.1만
18-02-19 조회 7,933
18-02-15 조회 6,247
18-02-14 조회 1.1만
18-02-13 조회 1.2만
18-02-12 조회 5,504
18-02-09 조회 7,257
18-02-08 조회 1.1만
18-02-08 조회 5,723
18-02-07 조회 9,935
18-02-06 조회 8,224
18-02-06 조회 6,702
18-02-05 조회 6,009
18-02-05 조회 9,315
18-02-04 조회 9,460
18-02-03 조회 6,530
18-02-03 조회 7,300
18-01-31 조회 5,913
18-01-31 조회 6,318
18-01-31 조회 1만