Razick
Razick

Reputation: 814

DateTime problems with PHP & MySQL

This should be a simple question since I assume I'm just doing something stupid, but here goes:

I have an email verification "token" that is sent via email as a get variable in the url to the verification page. This variable is checked against the 'tokens' table in the MySQL database and then the current time is checked against the expiration date.

Right now, I am writing the code to register the user and generate the token. It all works great, but the expiration date is coming out wrong.

The expiration date is obtained using this code:

$expires = date('Y-m-d H:i:s', time() + $settings['token_exp']);

The variable $setting['token_exp'] is assigned the value 24 * 3600 (24 hours in seconds).

However, the value in the database is 6 hours ahead of the expiration date (which is generated by MySQL CURRENT_TIMESTAMP. The timezone for MySQL is correct since it gives the current time, and the PHP timezone doesn't seem to be the cause either because even using 24 * 3600 * 4, the result is the exact same time and date. Even multiplying the 24 hours by 1000 doesn't change anything.

Any help on this bizarre issue would be appreciated.

Upvotes: 0

Views: 141

Answers (1)

Nouphal.M
Nouphal.M

Reputation: 6344

If you are trying to set an expiration after one day try

$expires = date('Y-m-d H:i:s', strtotime('+1 day'));

Upvotes: 3

Related Questions