0

Hi Guys,

I'm starting on a new project, it's a login page, let say I have a sql column[dateReg], it is the time the user registered or change his password, then everytime he login, I want to compare his login date to the dateReg and if the next time he login exceeds 30 days from the dateReg, he will not be able to login but will ask to change his password, any idea or piece of code on how to start it? Please help.

Thank You

3
Contributors
4
Replies
6
Views
4 Years
Discussion Span
Last Post by broj1
1

When you check login of a user;
set Exp date from reg date like

$expDate = strtotime(date("Y-m-d", strtotime($regDate)) . " +30 days");

Set your select query like

SELECT * FROM UserTableName WHERE ($expDate >= DATE(NOW()))

If this query returns values .. set user is loged in

else redirect to login page

Edited by Bachu

0

everytime I run this code

$expDate = strtotime(date("Y-m-d", strtotime($regDate)) . " +30 days");

I get an integer like this 1360800000, how to deal with it?

0

The value you are getting is a Unix timestamp which is time expressed in number of seconds after 1.jan. 1970. You can convert from/to Unix time here. The fact is that php date function uses unix timestamp and has ways of converting it to variety of formats, as Bachov Varghese posted above. And be careful, mysql timestamp differs from unix timestamp so do not mix them.

Hope I added a bit of clarification, not confusion.

Edited by broj1

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.