Restricting a login based on timestamps

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Restricting a login based on timestamps

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Restricting a login based on timestamps

Post 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
User avatar
evilchris2003
Forum Contributor
Posts: 106
Joined: Sun Nov 12, 2006 6:43 am
Location: Derby, UK

Re: Restricting a login based on timestamps

Post by evilchris2003 »

Thanks Jcart

thought there would be a simple way of doing it
Post Reply