Jump to content

Archived

This topic is now archived and is closed to further replies.

dual_alliance

In Need of Robot/Dummy Code

Recommended Posts

Hello,

I'm not sure if its called dummy or robot code but it sounds like what l need.  What l need is a code that once a day "-1" from the database,  this is so when the user is banned for x number of days each day the number reduces.  I would be very grateful if you could help me.

Thankyou,

dual_alliance

Share this post


Link to post
Share on other sites
what you need to do is set up a PHP script to do what you're after (the query only), and then, you just set up a CRON job to run it for you. if you have shell access to your server, just type "crontab -e" from your command line, then hit "i" to enter insert mode and enter the following job:

[code]
0 0 * * * php /path/to/file/myFile.php
[/code]

basically, that tells the script to run at midnight every day, so if your script is updating your database correctly, you're good to go. obviously "/path/to/file" needs to be the path on your server to the correct location.

hope this helps

Share this post


Link to post
Share on other sites
Thanks that helped allot, l just have one small problem in that l dont have shell access to my server as l am developing it on a cheap shared server is their any other alternative?

Share this post


Link to post
Share on other sites
do you have CPanel or another way to access CRON jobs through a web interface? if so, just set it up through there.

Share this post


Link to post
Share on other sites
On a side note, there are much easier ways of doing this. You could write the ban ending date into the database in a DATE field and later compare it with the current time. If the ban ending date is in the future, the user is still banned.

Share this post


Link to post
Share on other sites
Sorry for replying so late.  Well l do have a type of cPanel but it is just a basic one.  True that is an easier alternative but l am making a game and l need it to give resources to player every 15 minutes so having a date would not be very efficient but it could work for the ban system but l would rather have it to display how many days they are banned for if l can help it.

dual_alliance

Share this post


Link to post
Share on other sites
[quote]it could work for the ban system but l would rather have it to display how many days they are banned for[/quote]

Assuming you have a table called "bans" with columns (INT id,) INT user and DATE ban_ends, this query returns the remaining ban days as "days_left":

[code]SELECT DATEDIFF(ban_ends, CURDATE()) days_left FROM bans WHERE user = xx;[/code]

Share this post


Link to post
Share on other sites
Thanks acdx it looks like a good idea l'll give it a go.  Still it leaves me with the problem of how to get a piece of code running every 10 - 15 minutes without using a CRON job.  If anyone has any ideas please let me know.

Thanks

dual_alliance

Share this post


Link to post
Share on other sites
Rather than having a cron job could you not just check the ban date of the user trying to login and if the ban date is in the future you know not to let the user login.

Share this post


Link to post
Share on other sites

×

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.