Forum Moderators: coopster & phranque

Message Too Old, No Replies

Help needed with sessions

how to delete after a certain time?

         

habitat675

6:57 pm on Oct 20, 2002 (gmt 0)

10+ Year Member



Hello,

I'm wondering if anyone can help me with this: I'm working on a "who's logged in" type of thing using sessions. I have them being written to a certain directory on my server so I can just extract the file names. The question is how would I set this so the session would be deleted a certain amount of time after being written?

Thanks for any help.
-erin

littleman

7:04 pm on Oct 20, 2002 (gmt 0)



You could set up a cron job that does a date/time check and then use 'unlink' to delete them. You may have to open the directory, grab all the files and test each file one by one for the time stamp, if the files are older then X then you delete them.

amoore

7:08 pm on Oct 20, 2002 (gmt 0)

10+ Year Member



Here is a thread in which we beat this to death:
[webmasterworld.com...]

My theory is that you should put a timestamp on your sessions table, and then either run a cronjob to delete old sessions, or when someone logs in, delete all of their sessions that are older than some threshhold. Those seem the most reasonable and easiest to implement.

Good luck!

-Andy

habitat675

7:39 pm on Oct 20, 2002 (gmt 0)

10+ Year Member



thanks, but is there a way to do this without sql? I just have the files written to the directory and nothing else. This is where I'm having the problem

? cron job? makes no sense to me.

-erin

amoore

7:52 pm on Oct 20, 2002 (gmt 0)

10+ Year Member



Sure. I don't understand how you're keeping session information, but it sounds like you're making a new file for each user session. In that case, where I say "delete a session", you delete a file.

So, you can either regularly run a program that will delete all files older than some threshold, or when someone logs in, you can delete all of their older sessions, or delete the ones older than some threshold (so that they can be logged in twice at the same time)

? cron job? makes no sense to me.

If you're asking what a cron job is, I described it a bit in that thread to which I referred you. It's a way by which you can have commands executed on a regular basis. If you're on a windows machine, I think there's something like a command scheduler you can use or something like that. You can use this so that you can regularly delete old sessions.