Page 1 of 2
Expire?
Posted: Wed Mar 12, 2003 9:06 pm
by Mr. Tech
Hi!
I am wanting to write a members script where their subscription expires in a months time. How do I do that? Would it have something to do with time()?
What code would I need? Thanks!
Posted: Wed Mar 12, 2003 9:19 pm
by net7
Now, that depends. Are you storing the usernames in a database? Do they require passwords? You could use cookies, but that probably wouldn't be the best way to approach it.
When the user signs up you could along with entering the username and password in the database add the date or time. Then if when you have users login you could check to see if it has been 30 days since they first registered. If it has, then delete their account.
Or you could make and admin page and ever time you run it it would check all the users dates are less than 30 days old.
Hope this helps.
Posted: Wed Mar 12, 2003 9:23 pm
by craigh
don't delete the account, simply disable it. Create a column in the DB 'enabled' and make it default to 'Y' and after 30 days change it to 'N'. Then check their enabled status before allowing one to log in. I assume that you would want to keep their info around or allow them to re-enable the account for some reason - if not, then delete them I guess.

Posted: Wed Mar 12, 2003 9:27 pm
by Mr. Tech
Thanks both of you!
I use MYSQL to store their username and password. I am actually adding it to phpnuke. In the dB they have user_regdate and the format for it is Mar 12, 2003. Can i use that at all?
Posted: Wed Mar 12, 2003 9:33 pm
by craigh
yeah sure, see the mktime and date functions in the PHP manual at php.net to see how.
Posted: Wed Mar 12, 2003 9:36 pm
by Mr. Tech
So I would do this:
echo date ("Mar 12, 2003", mktime (0,0,0,12,32,1997));
And that would give me something like:
33213214541201
?
Thanks so much for your help!
Posted: Sun Mar 16, 2003 5:33 pm
by Mr. Tech
Anyone have any ideas?
Posted: Sun Mar 16, 2003 8:12 pm
by McGruff
My idea would be to dump the horror that is php nuke and write your own CMS but that's maybe not very helpful.
Posted: Sun Mar 16, 2003 9:30 pm
by Mr. Tech
No... not helpful at all.... Don't worry about phpnuke, I just want to work out this code first

Posted: Mon Mar 17, 2003 2:02 am
by twigletmac
What type of field is user_regdate?
Mac
Posted: Mon Mar 17, 2003 2:38 am
by junrey
Hope that this would help.
One thing that you need to consider is the data type of your
user_regdate field. If it is a
timestamp field then it would be ok but if it is not, then you need to use
mktime function to convert it to timestamp.
To determine the timestamp of the current date, you may try the following code:
Code: Select all
$today = getdate();
// just in case you will consider the time, hour : minute : seconds
$currentTimestamp=mktime($todayї'hour'], $todayї'minute'], $todayї'second'], $todayї'mon'], $todayї'mday'], $todayї'year']);
// then determine the difference between the date of registration and the
// current timestamp. Supposing that you have the variable
// $regTimestamp that serves as the timestamp of the registration
$diff = $currentTimestamp - $regTimestamp
// the $diff variable now contains the difference in seconds. so u may
// need to divide it with 3600 to determine the number of days.
Hope that this helps.
Junrey
Posted: Mon Mar 17, 2003 3:05 am
by Mr. Tech
Well, I don't have timestamp so I'll have to use mktime. The date format in the db looks like this:
Mar 12, 2003
What mktime code would I need to use to convert that?
Thanks a heap for your help junrey!
I appreciate it!
Thanks
Ben
Posted: Mon Mar 17, 2003 3:10 am
by twigletmac
Is the date really not in a DATE field? Is it in a VARCHAR field?
Mac
Posted: Tue Mar 18, 2003 3:19 am
by Mr. Tech
VARCHAR. Is that bad?
Thanks for all your help!

Posted: Tue Mar 18, 2003 3:46 am
by twigletmac
Personally I think storing dates in MySQL in anything other than DATE, DATETIME, TIMESTAMP or as a UNIX timestamp in an INT column is pointless as it leads to truly unneccessary hassle when you try and sort or print these dates.
Anyway, you could use PHP to work out whether or not membership had expired (was 30 days later than subscription date) by doing:
Code: Select all
<?php
$db_date = 'Mar 12, 2003';
$registered_date_timestamp = strtotime($db_date);
$thirty_days = 30*24*60*60;
$now = time();
$expired = $now - $thirty_days;
if ($registered_date_timestamp > $expired) {
echo 'ok';
} else {
echo 'expired';
}
?>
Some of the code is redundant but is there to show logic more than anything.
Check out:
http://www.php.net/strtotime
http://www.php.net/time
Mac