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

Recommended Answers

All 4 Replies

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

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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.