Page 1 of 1

Restricting a login based on timestamps

Posted: Sun Feb 24, 2008 2:13 pm
by evilchris2003
Hi guys

Can anyone point me in the direction of a tutorial or some such material on using a timestamp against a user login

Basically I have a registration script which picks up the date a user registers. I want to take that info and allow access for a set time before they have to pay to use the site say 14 days now im sure I can fix it to just take the date and add say 14 days to it before denying access but is it as simple as writing if statements to get the code to recognise when the month changes, or is it better to do this in the SQL ?

Thanks in advance

Re: Restricting a login based on timestamps

Posted: Sun Feb 24, 2008 4:39 pm
by John Cartwright
Create another datetime field, and call it something like 'expirydate', each time they make a payment increment this field by x amount of days,

Code: Select all

UPDATE users SET expirydate = ADDDATE(NOW(), INTERVAL 14 DAY) WHERE id=$userid
Then simply check if

Code: Select all

SELECT * FROM users` WHERE expirydate < NOW() AND id = $userid
to see if the the user is valid

Re: Restricting a login based on timestamps

Posted: Mon Feb 25, 2008 12:33 am
by evilchris2003
Thanks Jcart

thought there would be a simple way of doing it