Here's what it looks like, without the stuff that wouldn't interest you anyway:
The page you want it to be called from:
Code: Select all
<?php
require_once('includes/auth.php');
//...some other stuff
?>
*Explanation of including:
include() Simply include a php file and treat the code as the code of the actual page. Quits with a warning upon failure.
include_once() Same as above, but subsequent inclusion of the same file will be ignored.
require() Same as include(), but terminates the script on failure.
require_once() Same as above, but subsequent inclusion of the same file will be ignored.
My auto.php file (from a community website I made):
Code: Select all
<?php
//...some stuff
/*---Do cron job--*/
$cjtime = (int) implode(file('data/cronjob.txt')); //Open the file (file()) and implode() it to remove carriage-returns.
if (time() - $cjtime > 300) { //Run the following every 300 seconds
//NOTE: YOU CAN IGNORE EVERYTHING BELOW THIS LINE.
//I LEFT IT THERE FOR DEMONSTRATIVE PURPOSES!
$rescount = 0;
$vuid = array();
$iuid = array();
$quid = array();
$vsize = array();
$isize = array();
/* Count contrib.s */
$sql = 'SELECT userid, size FROM '.$conf['tbl_images'];
$rs = mysql_query($sql);
while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
$iuid[] = $row['userid'];
$isize[$row['userid']] += $row['size'];
$rescount++;
}
$sql = 'SELECT userid, size FROM '.$conf['tbl_videos'];
$rs = mysql_query($sql);
while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
$vuid[] = $row['userid'];
$vsize[$row['userid']] += $row['size'];
$rescount++;
}
$sql = 'SELECT userid FROM '.$conf['tbl_quotes'];
$rs = mysql_query($sql);
while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
$quid[] = $row['userid'];
$rescount++;
}
$fp = fopen('data/rescount.txt', 'w');
fwrite($fp, $rescount);
fclose($fp);
$iuid = array_count_values($iuid);
$vuid = array_count_values($vuid);
$quid = array_count_values($quid);
$sql = 'SELECT id FROM '.$conf['tbl_users'];
$rs = mysql_query($sql);
while ($row = mysql_fetch_array($rs, MYSQL_ASSOC)) {
$uid = $row['id'];
$ucount[$uid] = $iuid[$uid] + $vuid[$uid] + $quid[$uid];
$uquota[$uid] = $isize[$uid] + $vsize[$uid];
}
foreach ($ucount as $u => $c) {
$sql = 'UPDATE '.$conf['tbl_users'].' SET contributions = '.$c.' WHERE id = '.$u;
mysql_unbuffered_query($sql);
}
foreach ($uquota as $u => $q) {
$sql = 'UPDATE '.$conf['tbl_users'].' SET quota = '.$q.' WHERE id = '.$u;
mysql_unbuffered_query($sql);
}
/* Generate new cron time */
$fp = fopen('data/cronjob.txt', 'w');
fwrite($fp, time());
fclose($fp);
}
?>