?
Solved

setting expiry dates in php or mysql

Posted on 2012-03-16
3
Medium Priority
?
274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 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 111

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

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

765 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