1

For my current project (using PHP - Codeigniter ) user can upload there photos to the server. If the user is not registered / logged in I am creating a temporary id for the user and creates a folder with same name. And after logging in/ register I can change the folder name to the user ID.

So if the user is not authenticating identity I need to delete that entire folder from my server.

And the problem I am facing is that I need to know when ever the session is no longer active. So I could delete the folders.

The pobablities I found are when closing the browser, if the user system gone switch off, etc I need to delete those folders.

It will be great help if some one could suggest me how to implement this functionality.

Some js functions could detect through any browser actions. I think it willl be better to have a comination of js and server side codes,

Thanks in advance.

sarath
  • 56
  • 12
  • 4
    Please refer http://stackoverflow.com/questions/13246378/detecting-user-inactivity-over-a-browser-purely-through-javascript – yojna Jan 12 '16 at 09:31
  • but its for user inactivity for an idle time. And it works only when the browser is open. (So the counter could find track the time out ) – sarath Jan 12 '16 at 09:35
  • 2
    What does `delete folder from browser` mean? Assume that means server... use a temp directory until user logs in...and cron job to do cleanup – charlietfl Jan 12 '16 at 09:40
  • @charlietfl yeah I meant to delete form the server sorry for the confusion – sarath Jan 12 '16 at 12:01
  • Yes, best practice here would probably be to put all the unregistered user's files in a `tmp` folder, then run a `cron` job to clean that up daily, or something of that nature. You could also, do a simple database register of active sessions, and run a heartbeat on the client's browser that updates last activity time. Then reference that in your cron job to skip over any active sessions. – Lionel Ritchie the Manatee Jan 12 '16 at 16:33
  • @LionelRitchietheManatee thank you for introducing me cron job. I was not aware of that, My plan was to run the script on a regular intervel (like once in 3 days) – sarath Jan 13 '16 at 12:01

0 Answers0