0

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.

1
  • Seems to work fine here... eval.in/100487 Commented Feb 11, 2014 at 14:14

1 Answer 1

3

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

$expires = date('Y-m-d H:i:s', strtotime('+1 day'));
Sign up to request clarification or add additional context in comments.

1 Comment

I tried this and everything else I could find. I thought I had fixed it when I realized that the ini file wasn't registering the correct timezone and instead defined it by ini_set(), but the date was still wrong. I decided to use DATE_ADD(NOW(), INTERVAL 1 DAY) in the SQL and that worked fine. I am sure it's some unrelated mistake in my code causing this, so I'll accept your answer because despite my results, I know you are right.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.