Solved

setting expiry dates in php or mysql

Posted on 2012-03-16
3
267 Views
Last Modified: 2012-04-05
Just asking for advice. when the client registers on the site, I send an email to their email address they provided for validation purposes, in the email they have a link and a validation code, I want to expire this code x-hours after registration, is it better to store the registration timestamp and in the prgramming count the x-hours, or should I also store the expiry 'DATETIME' ?
0
Comment
Question by:prowebinteractiveinc
3 Comments
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 37730288
Doesn't really matter, just pick a method.  I think I would do the arithmetic when they register so I can use a '<' comparison on the expiration DATETIME.
0
 
LVL 17

Expert Comment

by:nanharbison
ID: 37730289
In my experience, the timestamp is easier to manipulate in arithmetic, and you will be subtracting to see if the number of hours has expired.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 37734936
This article has some ideas about how to use DATETIME values in PHP and MySQL.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html

I would store the ISO-8601 DATETIME string of the expiration in their row of the table.  I find this easier to read than an integer.  If they have three hours to confirm the registration, you might do something like this:
$expiry = date('c', strtotime('now + 3 hours));

Your confirmation query would look something like this:
UPDATE userTable SET confirmed='Y' WHERE key='$key' AND expiry >= NOW

If they fail to confirm, this sort of thing would remove the entry from the table.
DELETE FROM userTable WHERE confirmed<>'Y' AND expiry < NOW
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now