Page 1 of 1

BEst way to use time.

Posted: Fri Nov 24, 2006 12:52 pm
by a94060
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?

Posted: Fri Nov 24, 2006 8:26 pm
by evilchris2003
use a cookie or session with an expiry time limit that prevents access

Posted: Fri Nov 24, 2006 8:33 pm
by a94060
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?

Posted: Fri Nov 24, 2006 8:35 pm
by evilchris2003
well set the cookie have a variable that counts the time a user is on the page then subtract the variable time from the cookie time to give you the time remaining and overwrite the cookie

little bit long winded but should work

Posted: Fri Nov 24, 2006 8:37 pm
by a94060
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?

Posted: Fri Nov 24, 2006 8:44 pm
by evilchris2003
sorry java script aint my thing at all

ive used Java in the past but not Javascript and my exp of Java is limited at best

but im sure it is possible as long as you output the time in the browser somewhere as JS is client side

Posted: Fri Nov 24, 2006 8:51 pm
by a94060
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?

Posted: Fri Nov 24, 2006 8:55 pm
by evilchris2003
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

Code: Select all

echo $_SESSION['timeleft'];
then use the JS to see that value and display a count down

Posted: Fri Nov 24, 2006 9:03 pm
by a94060
Well,if i set this cookie,will it be able to be read by perl? I would like to know this because i want to be able to protect the script. I feel kinda stuck now,but im going to sleep now,thanks anyways.

Posted: Fri Nov 24, 2006 9:04 pm
by evilchris2003
i dunno perl in any way so i cant answer that

Sleep well :D

Posted: Fri Nov 24, 2006 10:25 pm
by DaveTheAve
The best way to use my "time" is making money. :lol:

Posted: Fri Nov 24, 2006 11:28 pm
by volka
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?
A simple texteditor would do but there are also plugins for all common browsers that allow changing cookie data on the fly.
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?
Maybe Possible. This script then would do what?

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.