Jump to content
MakeWebGames

How do you Create a Cron Job


modernmafia

Recommended Posts

I'm familiar with cron jobs at a McCodes level. Basically, you need to create a file, which includes queries/content that you want to be executed every x minutes/hours/days/weeks.

So, say you want something to be executed every day. First we would create a file, something like;

crons/1day_something.php

And this is what the content of that file will look like;

 <?php
/*
* Establish database connection for database queries
* Cron example, 1 day.
*/
$code = "XXX"; /* Change this code, so only you know it, so a 3rd party cannot manually execute the cron */
if(!$_GET['code'] OR $_GET['code'] != $code) {
exit; /* The script will not continue */
}

$message = "This\nEmail\nWill\nSend\nEvery\nDay";
$message = wordwrap($message, 70);

$get = mysql_query("SELECT `email` FROM `user_accounts` WHERE `email`!=""");
while($r = mysql_fetch_array($get)) {
mail("{$r['email']}", "5 Day email", $message);
}

?> 

 

Now we have the file, let's set up the cron.

a0a89869feb58b48eb4244979a5f2ae4.png

Now, this will execute the file crons/1day_something.php every day, automatically.

~sniko

Link to comment
Share on other sites

Just to note you dont always need to use a code at the end of a Cron url and even if users manage to find the cron file to run, It still wouldnt work for them as its being called for by a file with a function to actually run the cron

As i said earlier (..and this isn't shouting at you :P) my cron experience comes from McCodes, and if you, for example, go to http://www.a-random-game.com/cron_hour.php?code=code as a user, it still would run. From my experience anyway.

Maybe I interpreted your reply wrong, but you were saying that we don't need a ?code as it wouldn't run anyway? I think it would. Or are you saying, something else?

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...