删除会话文件从创建一段时间后 [英] delete session files after a time from creation

查看:122
本文介绍了删除会话文件从创建一段时间后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我救了我会从/ temp目录中的另一个目录。
比方说 /会话目录。(使用 session_save_path(会议)

I am saving my sessions in another directory from /temp directory. say /session directory.( using session_save_path("session") )

也有一个code后从创建和注销10小步舞杀了会议。

also, there is a code to kill the session after 10 minuets from creation and logout.

但我提到,如果与例如用户登录关闭了他的电脑,我的注销和会话摧毁code剂量无法运行,因此会话文件将保留在会话目录。

but I mentioned that if the user logs in and for example shut down his computer, my log out and session destroy code doses not run, so the session file will remain in the session directory.

我想知道的是,有一种方法来删除会话文件 /会话从创建一段时间后?

I wanted to know is there is a way to delete session files in /session after a time from creation?

我用这个code它

  if ($handle = opendir('sessions')) {

    while (false !== ($file = readdir($handle))) {
        if (filectime($file)< (time()-600)) {  // 600 = 10*60
        unlink($file);
        }
    }
  }

但是,没有工作,我认为这可能不是由 filectime($文件)获得的创建时间

感谢

推荐答案

感谢,但我想我可以独自解决这个问题。

thanks but I think I could solve it by myself

解决方案很简单

  if ($handle = opendir('sessions')) {

  foreach (glob("sessions/sess_*") as $filename) {
    if (filemtime($filename) + 400 < time()) {
      @unlink($filename);
    }
  }

  }

这篇关于删除会话文件从创建一段时间后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆