SMF Shop

SMFShop => SMFShop Announcements => Topic started by: Daniel15 on February 10, 2006, 08:43:23 pm

Title: Bank interest without cron job? Read this!
Post by: Daniel15 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 (http://www.www.daniel15.com/forum/index.php?topic=95.msg349#msg349) for more details
Title: Re: Bank interest without cron job? Read this!
Post by: tazpot 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 (http://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  :)
Title: Re: Bank interest without cron job? Read this!
Post by: Vinspire 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 (http://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:
Title: Re: Bank interest without cron job? Read this!
Post by: Daniel15 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
Title: Re: Bank interest without cron job? Read this!
Post by: Vinspire 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
Title: Re: Bank interest without cron job? Read this!
Post by: Levita on June 22, 2006, 03:44:41 am
Ehm, sorry
but how to call the script myself?
Title: Re: Bank interest without cron job? Read this!
Post by: Levita on June 23, 2006, 03:43:29 am
*bump* ?
Title: Re: Bank interest without cron job? Read this!
Post by: SuperTongue 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?
Title: Re: Bank interest without cron job? Read this!
Post by: TheGamer on August 10, 2006, 02:07:49 pm
Completely normal. :)
Title: Re: Bank interest without cron job? Read this!
Post by: Daniel15 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...
Title: Re: Bank interest without cron job? Read this!
Post by: prisoner 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

Title: Re: Bank interest without cron job? Read this!
Post by: Daniel15 on October 27, 2006, 06:41:57 pm
Thanks prisoner, I've correct my (stupid) mistake :P
Title: Re: Bank interest without cron job? Read this!
Post by: Basil Beard 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.
Title: Re: Bank interest without cron job? Read this!
Post by: Daniel15 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 ;) 
Title: Re: Bank interest without cron job? Read this!
Post by: jdv 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
Title: Re: Bank interest without cron job? Read this!
Post by: jdv on December 19, 2006, 11:13:54 am
Am i the only one having trouble? :(
Title: Re: Bank interest without cron job? Read this!
Post by: Daniel15 on December 20, 2006, 05:25:55 pm
Quote
Is the new shop version 2.3 suppose to calculate bank interest on its own?
Yes, that's what the dointerest.php file does (unless you mean something else?)

Quote
Also noticed it only likes whole number like 1 or 2, and wont take 0.02
That's fixed in the development version of SMFShop, and will be fixed in the next release. I posted a fix on how to achieve this (search this forum for it)
Title: Re: Bank interest without cron job? Read this!
Post by: jdv on December 20, 2006, 09:14:59 pm
But a cron job has to be established to run the dointrest right? And if so, whats the path i run on the cron job? Im asking because i thought this would be done automatically (calculate interest)

Starting my scavenger hunt on the other fix.

thanks.
Title: Re: Bank interest without cron job? Read this!
Post by: jdv on December 20, 2006, 09:43:29 pm
Im searching for the bank interest change question i had above. I get the same results when i do different searches on the forum. If someone could point me to the thread that talks about it regards i would appreciate it.

My host dont have cron job. im trying to use cronjobs.org but it doesn't run it.
Title: Re: Bank interest without cron job? Read this!
Post by: Maniakc on January 25, 2007, 09:05:59 am
This doesnt work for me, I get a white screen then nothing happens when I run the script in IE. Am I supposed to run it some other way?

Got it to work on another PC!  :)
Title: Re: Bank interest without cron job? Read this!
Post by: slackerpunk on July 07, 2008, 01:42:53 pm
instead of calling dointerest.php from inside Sources/Shop

I used this file and setup the absolute path to SSI.php and placed it inside Sources/shop and saved it as interest.php and made a cron using interest.php and it seems to work. Could there be an issue with dointerest.php that comes with the package? I am using 3.0 by the way
Title: Re: Bank interest without cron job? Read this!
Post by: mich0psp on September 02, 2008, 02:57:12 pm
I've been fighting with interest for 2 weeks now. For some reason no matter what I did I couldn't get the cron job to work from CPanel. Anyhow... I just found this thread, made my cronjob at http://www.onlinecronjobs.com (free) and tada! Instant interest!

I had to share since the site allows you to test your cron jobs so you don't have to wait 24 hours to check if it works. Thought you all would be interested.

Now I'm gonna see if I can set it that way with the Lottery job too. Will let you know if that works. :smitten:
Title: Re: Bank interest without cron job? Read this!
Post by: wayne_r_uk on October 10, 2008, 04:50:21 am
got it working!!!

great!