Solved

setting expiry dates in php or mysql

Posted on 2012-03-16
3
270 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 109

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

773 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