djfox Posted January 5, 2008 Share Posted January 5, 2008 Accounts on my site can have upgrades but the upgrades are not permanent. For the moment, I have to hand-edit accounts if their upgrades expire. But I would like for the upgrades to expire on their own. What would be the best way for me to do this? Quote Link to comment https://forums.phpfreaks.com/topic/84649-solved-what-is-the-best-way-to-handle-account-upgrade-expirations/ Share on other sites More sharing options...
revraz Posted January 5, 2008 Share Posted January 5, 2008 How do they expire? If by date, then you need to run a cron job daily (or however often you want to check) and have it take appropriate action. Or you can just have it check when they log in if you don't need it to do it while they are not logged in. Quote Link to comment https://forums.phpfreaks.com/topic/84649-solved-what-is-the-best-way-to-handle-account-upgrade-expirations/#findComment-431388 Share on other sites More sharing options...
djfox Posted January 5, 2008 Author Share Posted January 5, 2008 Cron job? Ok, the dates are entered by strftime("%B\ %e\,\ %Y %H:%M:%S", time()); How could I tell the cron job to check to see if it`s that date (the expiration date) before it degrades the account back down? (I`ve only recently learned about cron jobs so I`m still pretty new with it.) Quote Link to comment https://forums.phpfreaks.com/topic/84649-solved-what-is-the-best-way-to-handle-account-upgrade-expirations/#findComment-431400 Share on other sites More sharing options...
thefollower Posted January 5, 2008 Share Posted January 5, 2008 For me with my premium accounts i set it by days so like 30 days left. Then with a cron once a day subtract 1 day... but also does a check like : if days left == 0 then expire the account This does it daily so it checks everyone. If you have it in like minutes or seconds or hours then u would be wise to have a cron run that once on each minute/hour. If it is once a minute try to make it efficient as possible so it doesn't hurt your server processing specially if its got to check like 100 thousand users. Quote Link to comment https://forums.phpfreaks.com/topic/84649-solved-what-is-the-best-way-to-handle-account-upgrade-expirations/#findComment-431403 Share on other sites More sharing options...
djfox Posted January 5, 2008 Author Share Posted January 5, 2008 For me with my premium accounts i set it by days so like 30 days left. Then with a cron once a day subtract 1 day... but also does a check like : if days left == 0 then expire the account This does it daily so it checks everyone. If you have it in like minutes or seconds or hours then u would be wise to have a cron run that once on each minute/hour. If it is once a minute try to make it efficient as possible so it doesn't hurt your server processing specially if its got to check like 100 thousand users. Hm, interesting idea. How do I tell it to check to see if the days is 0 and expire the account? Quote Link to comment https://forums.phpfreaks.com/topic/84649-solved-what-is-the-best-way-to-handle-account-upgrade-expirations/#findComment-431404 Share on other sites More sharing options...
revraz Posted January 5, 2008 Share Posted January 5, 2008 Try it without a cron job, and just do the check and action each time they log in or visit the site (if you use cookies). Quote Link to comment https://forums.phpfreaks.com/topic/84649-solved-what-is-the-best-way-to-handle-account-upgrade-expirations/#findComment-431407 Share on other sites More sharing options...
thefollower Posted January 5, 2008 Share Posted January 5, 2008 do a query along the lines of: for removing DELETE FROM tablename WHERE DaysLeft = 0 deletes all users from the user table where daysleft is zero for reducing days: UPDATE tablename SET DaysLeft=DaysLeft-1 WHERE DaysLeft > 0 So it will reduce days left by 1 where people have more than their last day left. Quote Link to comment https://forums.phpfreaks.com/topic/84649-solved-what-is-the-best-way-to-handle-account-upgrade-expirations/#findComment-431409 Share on other sites More sharing options...
thefollower Posted January 5, 2008 Share Posted January 5, 2008 Try it without a cron job, and just do the check and action each time they log in or visit the site (if you use cookies). Could be unnecessary though depending on what your system is. If the user logs in 4 times in one day your checking 4 times. With a cron ran once a day your only checking each user once which makes it slightly more efficient and less server processing is needed... which would be what i would do personally. Quote Link to comment https://forums.phpfreaks.com/topic/84649-solved-what-is-the-best-way-to-handle-account-upgrade-expirations/#findComment-431412 Share on other sites More sharing options...
djfox Posted January 5, 2008 Author Share Posted January 5, 2008 do a query along the lines of: for removing DELETE FROM tablename WHERE DaysLeft = 0 deletes all users from the user table where daysleft is zero for reducing days: UPDATE tablename SET DaysLeft=DaysLeft-1 WHERE DaysLeft > 0 So it will reduce days left by 1 where people have more than their last day left. Mind reader. I was about to ask how to be sure that the cron job doesn`t make the value in the negatives. With a cron ran once a day your only checking each user once which makes it slightly more efficient and less server processing is needed... which would be what i would do personally. In order to do that to make the account upgrade go back down, would I be putting in something like: UPDATE userdata set level=1, status=Basic WHERE daysleft=0 AND level>1 Quote Link to comment https://forums.phpfreaks.com/topic/84649-solved-what-is-the-best-way-to-handle-account-upgrade-expirations/#findComment-431416 Share on other sites More sharing options...
revraz Posted January 5, 2008 Share Posted January 5, 2008 Yep, it all depends on what you want out of it. Some people want it to expire on the hour instead of everyday, so it would be better to check each person that logs in rather than run 24 cron jobs a day updating the entire DB. If people aren't active or don't come back, no reason to even check them. And it's just one line of code to check a date, not like it's massive overhead. Try it without a cron job, and just do the check and action each time they log in or visit the site (if you use cookies). Could be unnecessary though depending on what your system is. If the user logs in 4 times in one day your checking 4 times. With a cron ran once a day your only checking each user once which makes it slightly more efficient and less server processing is needed... which would be what i would do personally. Quote Link to comment https://forums.phpfreaks.com/topic/84649-solved-what-is-the-best-way-to-handle-account-upgrade-expirations/#findComment-431417 Share on other sites More sharing options...
thefollower Posted January 5, 2008 Share Posted January 5, 2008 do a query along the lines of: for removing DELETE FROM tablename WHERE DaysLeft = 0 deletes all users from the user table where daysleft is zero for reducing days: UPDATE tablename SET DaysLeft=DaysLeft-1 WHERE DaysLeft > 0 So it will reduce days left by 1 where people have more than their last day left. Mind reader. I was about to ask how to be sure that the cron job doesn`t make the value in the negatives. With a cron ran once a day your only checking each user once which makes it slightly more efficient and less server processing is needed... which would be what i would do personally. In order to do that to make the account upgrade go back down, would I be putting in something like: UPDATE userdata set level=1, status=Basic WHERE daysleft=0 AND level>1 Im going to assume that this is a game of some kind cos you have level? If so there is a simpler way For me i have this: DonatorDays When donator days = 0 u wont need a "Status" because in simple effect if donator days = 0 then they must be in "Basic" because they have no days left... that would reduce the amount of fields you need. Unless status has some other option other than basic even if you are not a donator? This then in turn if u have features only for donators then you just put a check before that feature like : "If donatordays > 0 then proceed" "If donatordays < 1 { echo ' must be donator'; } " Quote Link to comment https://forums.phpfreaks.com/topic/84649-solved-what-is-the-best-way-to-handle-account-upgrade-expirations/#findComment-431423 Share on other sites More sharing options...
djfox Posted January 5, 2008 Author Share Posted January 5, 2008 This then in turn if u have features only for donators then you just put a check before that feature like : "If donatordays > 0 then proceed" "If donatordays < 1 { echo ' must be donator'; } " Yes, those checks are done with what level the user is. Quote Link to comment https://forums.phpfreaks.com/topic/84649-solved-what-is-the-best-way-to-handle-account-upgrade-expirations/#findComment-431425 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.