BEst way to use time.
Moderator: General Moderators
BEst way to use time.
HEllo All,
I was thinking of trying to set a way to manage how long someone can acess a script. I would like to make it in a such a way that i can grant access to a script for an amount of time and then,disallow acces after they used their time. I was thinking that this could be possible by using a file that stored the date in a form of user:time and then have a crontab that would run every 10 mins or so checking to see if the time was up. I would make a file be written to once the user logged in and then have the crontab to check the time between the time written in and the time now. I would also make an if statment that would check if they are logged in. Does this sound possible to do the way i am saying?
I was thinking of trying to set a way to manage how long someone can acess a script. I would like to make it in a such a way that i can grant access to a script for an amount of time and then,disallow acces after they used their time. I was thinking that this could be possible by using a file that stored the date in a form of user:time and then have a crontab that would run every 10 mins or so checking to see if the time was up. I would make a file be written to once the user logged in and then have the crontab to check the time between the time written in and the time now. I would also make an if statment that would check if they are logged in. Does this sound possible to do the way i am saying?
- evilchris2003
- Forum Contributor
- Posts: 106
- Joined: Sun Nov 12, 2006 6:43 am
- Location: Derby, UK
Well, would the cookie way be much easier? I would just acheive this by setting a cookie? I want to make in such a way so that if i have 40 mins and i log in now for 10 mins and then log out,i can still logback in and use the 30 mins i have. how could i do this with cookies? would i set a cookie for the time we started and on logout,read the cookie and subtract the time started from the current time? then store this value in a database?
- evilchris2003
- Forum Contributor
- Posts: 106
- Joined: Sun Nov 12, 2006 6:43 am
- Location: Derby, UK
- evilchris2003
- Forum Contributor
- Posts: 106
- Joined: Sun Nov 12, 2006 6:43 am
- Location: Derby, UK
- evilchris2003
- Forum Contributor
- Posts: 106
- Joined: Sun Nov 12, 2006 6:43 am
- Location: Derby, UK
that would work (i dunno about cron ive never used it)
what i was meaning was use PHP to output the time in the browser
then use the JS to see that value and display a count down
what i was meaning was use PHP to output the time in the browser
Code: Select all
echo $_SESSION['timeleft'];- evilchris2003
- Forum Contributor
- Posts: 106
- Joined: Sun Nov 12, 2006 6:43 am
- Location: Derby, UK
- DaveTheAve
- Forum Contributor
- Posts: 385
- Joined: Tue Oct 03, 2006 2:25 pm
- Location: 127.0.0.1
- Contact:
A simple texteditor would do but there are also plugins for all common browsers that allow changing cookie data on the fly.a94060 wrote:is there a way that i can watch this via js or something? so that the person cannot go over the time that they get?
Maybe Possible. This script then would do what?a94060 wrote:i was thinking that maybe a cron cript would do to check the times in the table? Like i could select all values where start_time is set and then i could do a foreach to see if time()-start_time > 0. Would that work?
You could store the "stop time" within the session data (and you probably have something like that already or how do you track who's logged in and who's not?) and check that timestamp against time() whenever your "normal" scripts are executed, i.e. per request.