We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,183 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Login script with expiration date verification

Evening All,

I'm new here and new to PHP, so please take it easy on me! =]

I'm working on a php login script that would allow a user to enter their last name or their username in the username field and their password. Upon submit, check for a record with last name or username, password and expiration date is greater than todays date. I've got the username or last name and password part down and working.

Background info: the 'Expiration Date' field is a usual text field in the SQL db and i'm not going to be able to change that.

This is what i have so far:

$cur_date = date("n/j/Y");
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' or lastname='$myusername' and password='$mypassword' and 'Expiration Date' > $cur_date";

Thanks in advance everyone!

-Jacob

4
Contributors
3
Replies
7 Hours
Discussion Span
10 Months Ago
Last Updated
4
Views
GriffN84
Newbie Poster
1 post since Jul 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Hi

If &cur_date is a text field and not a MySql date field then I don't think >$cur_date will work, you need to change that field to a properly formatted date field, although I realise you say you can't. I'm not sure what to do about that. Maybe someone else has a suggestion?

Also I don't think you need ' ' round $myusername or $mypassword, my understanding is that is only used for numbers.

gilgil2
Junior Poster
102 posts since Aug 2011
Reputation Points: 10
Solved Threads: 2
Skill Endorsements: 0

Personally I'd have expiration date as unix timestamp (integer) or at the very least a date (unix format): Y-m-d.

$now = time();
$sql="SELECT * FROM `$tbl_name` WHERE (`username` ='$myusername' OR `lastname` ='$myusername') AND `password`='$mypassword' AND `expiry` > $now";

BTW - using more than one word for a field can be bothersome

diafol
Keep Smiling
Moderator
10,662 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,513
Skill Endorsements: 57

Hi,
ADDED LATER: MY post is late, so please consider diafol's response before this.

This is just a humble suggestion for your script. Why not use a unix timestamp instead of the actual human readable date.

For example, an account can have a date verification expiration two days from the date it was sent to the user. Both beginTime and expiry must be stored in the database.

  ## get the current time when the expiratio starts ticking.
  $beginTime = time();

  ## expire this in 1 day from the curTime above.
   //$expriry = strtotime('+1 day', $beginTime);

  ## we can use the above expiry or below..

  $expiry = strtotime("+24 hours", $curTime);

  ## now we can approximate if the expiry time has been exceeded or not.

  if(time() >= $expriry){

  echo "oops, your activation noticed had expired";

  }

  else{

  echo "Your ok..";

  }

The $beginTime above refers to the time recorded, when the expiration begins to countdown. The time() in the if statement is the current time, when the user access the account for activation.

veedeoo
Master Poster
735 posts since Oct 2011
Reputation Points: 298
Solved Threads: 130
Skill Endorsements: 13

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0630 seconds using 2.73MB