Author Topic: Bank interest without cron job? Read this!  (Read 29379 times)

Offline Daniel15

Bank interest without cron job? Read this!
« on: February 10, 2006, 08:43:23 pm »
Hi,
 Unfortunately, some people don't have access to cron jobs, and therefore ask me if there's a way to add the interest without using cron jobs.

First, create a file somewhere on your website. Give it a random name, maybe something like dointerest2342351.php. This is so members of your site don't know the name of the file, and therefore can't add the interest themselves. Put the following text in the file:
Code: (php) [Select]
<?php
/**********************************************\
| SMFSHOP (Shop MOD for Simple Machines Forum) |
|         (c) 2005 DanSoft Australia           |
|      http://www.dansoftaustralia.net/        |
\**********************************************/

//File: dointerest.php
//      The file to add interest to member's bank

//VERSION: 1.31 (Build 7)
//DATE: 10th December 2005

include("/home/[username]/public_html/forum/SSI.php");

$interest_rate $modSettings['shopInterest'] / 100;
db_query("UPDATE {$db_prefix}members
SET moneyBank = moneyBank + (moneyBank*
{$interest_rate})"__FILE____LINE__);

echo 
"Interest added at ".date("d/m/Y h:i:s A");
?>


Replace '/home/[username]/public_html/forum/' with the absolute URL of the forum. This can be found by going to SMF Admin Panel --> Edit Server Settings --> SMF Directory. It will look something like '/home/username/public_html/forum'.

Next, we use a utility that calls this script every day. There are several web-based cron tools, but most are in other languages. You can get a Windows program that will call the script every day, or, if you want to, you could just run the script yourself :)

Once you've set that up, your interest should now be working!

UPDATE: You may try to call the script via the Windows Task Scheduler. Please see this post for more details
« Last Edit: January 19, 2007, 04:12:28 pm by Daniel15 »

Offline tazpot

Re: Bank interest without cron job? Read this!
« Reply #1 on: April 24, 2006, 05:55:42 am »
I found a place that will let you set up a free web based cron job www.cronjobs.org/index.php
The only info you need to change are...

Name.....just make something up
URL http......ie www.yoursite.com/forum/your_bankinterest.php
Expire after........change to 999 because setting to 000 will give an error
HOUR.....set to 0am or whatever time you want

Hope this helps someone  :)
« Last Edit: April 24, 2006, 06:00:57 am by tazpot »

Offline Vinspire

Re: Bank interest without cron job? Read this!
« Reply #2 on: June 12, 2006, 01:38:38 pm »
I found a place that will let you set up a free web based cron job www.cronjobs.org/index.php
The only info you need to change are...

Name.....just make something up
URL http......ie www.yoursite.com/forum/your_bankinterest.php
Expire after........change to 999 because setting to 000 will give an error
HOUR.....set to 0am or whatever time you want

Hope this helps someone  :)

I am still waiting for a validation email from that site  :'( :'( :'(

Quote
Next, we use a utility that calls this script every day. There are several web-based cron tools, but most are in other languages. You can get a Windows program that will call the script every day, or, if you want to, you could just run the script yourself Smiley

UPDATE: You may try to call the script via the Windows Task Scheduler. Please see this post for more details

How to do this & i did follow the link .... and the link for the windows task scheduler is dead  :crazy2: :crazy2: :crazy2:

Offline Daniel15

Re: Bank interest without cron job? Read this!
« Reply #3 on: June 16, 2006, 09:03:45 pm »
Quote
and the link for the windows task scheduler is dead
Bah, my find-and-replace made the link incorrect!
Try this link instead: http://www.daniel15.com/forum/index.php?topic=95.msg349#msg349

Offline Vinspire

Re: Bank interest without cron job? Read this!
« Reply #4 on: June 18, 2006, 11:59:42 pm »
Nvm daniel. Manage to get it working by doing cron job in the cpanel   O0 O0 O0

Offline Levita

Re: Bank interest without cron job? Read this!
« Reply #5 on: June 22, 2006, 03:44:41 am »
Ehm, sorry
but how to call the script myself?

Offline Levita

Re: Bank interest without cron job? Read this!
« Reply #6 on: June 23, 2006, 03:43:29 am »
*bump* ?

SuperTongue

  • Guest
Re: Bank interest without cron job? Read this!
« Reply #7 on: August 10, 2006, 04:51:04 am »
I was wondering... All you have to do is visit http://url/forum/interest.php (or whatever I named it) to activiate it, right? Well I went to it and it was a blank page. Is this normal?

Offline TheGamer

Re: Bank interest without cron job? Read this!
« Reply #8 on: August 10, 2006, 02:07:49 pm »
Completely normal. :)

Offline Daniel15

Re: Bank interest without cron job? Read this!
« Reply #9 on: August 12, 2006, 02:43:14 pm »
Well, you should get a page saying 'Interest added at ' followed by the date... However, if you don't, it should be fine (as long as the interest is actually added)

For the 'do_interest.php' file, it won't work if you call it from your browser...
« Last Edit: August 12, 2006, 02:45:37 pm by daniel15 »

Offline prisoner

Re: Bank interest without cron job? Read this!
« Reply #10 on: October 24, 2006, 09:55:11 pm »
Hello,

there is a misstake in the script by Daniel15, i have correct them...

<?php
/**********************************************\
| SMFSHOP (Shop MOD for Simple Machines Forum) |
|         (c) 2005 DanSoft Australia           |
|      http://www.dansoftaustralia.com/        |
\**********************************************/

//File: dointerest.php
//      The file to add interest to member's bank

//VERSION: 1.31 (Build 7)
//DATE: 10th December 2005

include("/home/[username]/public_html/forum/SSI.php");
   
$interest_rate = $modSettings['shopInterest'] / 100;
db_query("UPDATE {$db_prefix}members
      SET moneyBank = moneyBank + (moneyBank*{$interest_rate})", __FILE__, __LINE__);
   
echo "Interest added at ".date("d/m/Y h:i:s A");
?>


The last "}" must be deleted, i assume he forgot this while editing original dointere4st.php

Now everything should working if you call the script from browser


Offline Daniel15

Re: Bank interest without cron job? Read this!
« Reply #11 on: October 27, 2006, 06:41:57 pm »
Thanks prisoner, I've correct my (stupid) mistake :P

Offline Basil Beard

Re: Bank interest without cron job? Read this!
« Reply #12 on: November 01, 2006, 12:30:03 pm »
Wow. I just happened to read this and find that it actually doesn't avoid cron jobs. A cron job just calls a script daily. If you can't do that, what can you do? Well, why not simply run interest whenever someone visits the shop... it takes a few database querys, but nothing fancy. Note that this only works if your members are active. Someone needs to log-on to trigger it. You could be fancy, and have it find the number of days in between failed interest days, but that would be tricky with leap years. I wanna keep this simple

Ok. Open shop.php, find

Code: [Select]
    $context['page_title'] = $txt['shop'];
    $context['linktree'][] = array(
        'url' => "$scripturl?action=shop",
        'name' => $txt['shop'],
);

Below this is where we will code. The first thing to do is to check if it is a new day or not. The best way to do this is to create a column in the Settings database table, which records the last time someone collected interest. So insert a row into that table with variable = 'InterestDate' and value = 0.

now add this code
Code: [Select]
$date = date('z') //find the current date. Z is the day of the year it is.
$olddate = $modSettings['InterestDate'] //last date you got interest

if ($date != $olddate) // if they are equal, do nothing. If they are not equal, time to collect interest.
{
$interest_rate = $modSettings['shopInterest'] / 100;
db_query("UPDATE {$db_prefix}members
  SET moneyBank = moneyBank + (moneyBank*{$interest_rate})", __FILE__,  __LINE__); // This gives interst copied from daniels script, so it should work.

$result = db_query("UPDATE {$db_prefix}settings
                                     SET value = {$date}
                                     WHERE variable = 'InterestDate'", __FILE__, __LINE__); //update the last time interest was collected
}

And that it. I havn't tested it(its 11:30 PM right now), but it should work. If not, just give me the error you get and I will try to fix it.
Arrrrr!

Offline Daniel15

Re: Bank interest without cron job? Read this!
« Reply #13 on: November 17, 2006, 08:08:57 pm »
Nice suggestion Basil Beard :) 
Quote
Wow. I just happened to read this and find that it actually doesn't avoid cron jobs. A cron job just calls a script daily. If you can't do that, what can you do?
  Well, I meant, if you don't have access to cron jobs on your server ;) 

Offline jdv

Re: Bank interest without cron job? Read this!
« Reply #14 on: December 16, 2006, 10:44:47 pm »
Is the new shop version 2.3 suppose to calculate bank interest on its own? I noticed its not and i have to force the bank int everyday. Also noticed it only likes whole number like 1 or 2, and wont take 0.02

Let me know if im doing it wrong or if you have a suggestion. Greatly appreciate.

John