Solved

setting expiry dates in php or mysql

Posted on 2012-03-16
3
273 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 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 110

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

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…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
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…

726 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