Jump to content

PHP Membership Cronjob


echo-tech
Go to solution Solved by fastsol,

Recommended Posts

Hi,

 

I have a question...

 

I have created a PHP system where you can purchase various membership systems (e.g Bronze, Silver and Gold). When the membership is purchased it updates the following:

 

Sets "package_bronze" to "1" 

Inserts date and time + 1 month into "bronze_exp_date" (e.g today is 16/07/2013, so it'll set the exp date to 16/08/2013)... 

 

I want to setup a cronjob so that every 5 minutes it'll run a PHP script to tell the database whether or not the users membership should have been set from "1" back to "0". 

 

I need some help with writing that code... 

 

I'm assuming it would be something like:

 

If a certain user's expiry date has passed then set the certain package variable date to 0 ...

 

Could anyone please help me with the mysql query for it and the php "if" statements?

 

Regards,

Echo-Tech 

Link to comment
Share on other sites

  • Solution
$today = date("d/m/Y");
mysql_query("UPDATE `table` SET `column` = 0 WHERE `expire_date` < $today");

I did a little assuming on the $today and expire_date, this may not work correctly depending on the format you have the date stored in the db.  If it's in a DATE format it might work right that way, otherwise I suggest reading up on the mysql date formats and queries for such things.

Link to comment
Share on other sites

I can't really see this being useful. Why not just wait until the user wants to login and check the expiry?

 

I can only see this as being useful if another system is accessing the data, but then it can check the expiry as well if you control that system.

 

Just a thought.

Link to comment
Share on other sites

Thanks fastsol I see how that works now...

 

I can't really see this being useful. Why not just wait until the user wants to login and check the expiry?

I can only see this as being useful if another system is accessing the data, but then it can check the expiry as well if you control that system.

Just a thought.

 

I suppose, but is there absolutely no way that the user can bypass the expiry date check? I want the system to be fast, if the user logs in and has 3 expiry dates to each package (for example) then it's going to take a while for the user to get logged in, not too long but it'll be long enough to be annoying after each check has to be complete...

Link to comment
Share on other sites

Even if you add a separate email task you still don't really need to add a cron job just to check the expiry date. You also don't really need separate 1/0 and date fields for each level. Just allow the date field to be null. Then you could check these conditions

 

if bronze_exp_date = null then they never had a subscription

if bronze_exp_date is a date, but expired then they had a subscription that expired

if bronze_exp_date is a date and not expired then they have a current subscription.

 

You can use a CASE statement to query pseudo-columns for this information:

SELECT
  CASE WHEN bronze_exp_date IS NULL THEN 1 ELSE 0 END as hasHadSubscription
  , CASE WHEN bronze_exp_date < CURDATE() THEN 1 ELSE 0 END as hasSubscriptionExpired
FROM blah
For convenience you could wrap that up into a VIEW and use that view anywhere you want to query such information.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.