Solved

setting expiry dates in php or mysql

Posted on 2012-03-16
3
269 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 83

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

929 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

11 Experts available now in Live!

Get 1:1 Help Now