Cronjob problem...

Connect with other users about what to run on your webhosting (and how to run it) here.
Post Reply
Mr Sweg
New to forums
New to forums
Posts: 5
https://www.youtube.com/channel/UC40BgXanDqOYoVCYFDSTfHA
Joined: Tue May 27, 2014 9:51 am

Cronjob problem...

Post by Mr Sweg »

/usr/www/mdg/public/donations/cronjob.php: line 1: ?php: No such file or directory
/usr/www/mdg/public/donations/cronjob.php: line 2: syntax error near unexpected token `"connectionfile.php"'
/usr/www/mdg/public/donations/cronjob.php: line 2: `include("connectionfile.php");'

cronjob.php:

Code: Select all

<?php
include("connectionfile.php");
include("config.php");

$auth = $_GET['p'];
if($auth == "test"){
	$q = $dbc->prepare("SELECT * FROM users WHERE used = ? AND expiration != ?");
	$query = $q->execute(array(
		1,
		0
	));
	$arr = $q->fetchAll();

	foreach($arr as $row){
		$newExp = $row['expiration'] - 1;
		$qT = $dbc->prepare("UPDATE users SET expiration = ?");
		$queryT = $qT->execute(array(
			$newExp
		));

		if($queryT){
			echo "The user with the SteamID of ".$row['steamid']." has expired another day<br>";
		}
	}
}else{
	echo "Authorization failed!";
}
?>
User avatar
Edge100x
Founder
Founder
Posts: 13120
Joined: Thu Apr 18, 2002 11:04 pm
Location: Seattle
Contact:

Re: Cronjob problem...

Post by Edge100x »

It appears that whatever is trying to run this script is not executing it correctly with the PHP interpreter executable. Make sure that it is set up to use /usr/bin/php.
Mr Sweg
New to forums
New to forums
Posts: 5
Joined: Tue May 27, 2014 9:51 am

Re: Cronjob problem...

Post by Mr Sweg »

Made it to:

Code: Select all

* * * * * /usr/bin/php ~/public/donations/cronjob.php
and now I get this...
Authorization failed!
User avatar
Spray
Former staff
Former staff
Posts: 630
Joined: Wed Dec 28, 2011 10:41 pm
Location: Oregon

Re: Cronjob problem...

Post by Spray »

The "Authorization failed!" error is because you're hitting this section of code:

Code: Select all

else{
   echo "Authorization failed!";
}
Looking over your code, in order to have the first if...else statement evaluate to true, the following must be set:

Code: Select all

$auth == "test"
You're populating your $auth variable via the superglobal array $_GET, which looks for variables passed to the current script via the URL parameters.

When running this script using the PHP interpreter on the command line, you are unable to pass query strings like you normally would through a webserver. If you're only going to use this as a cron script I would consider using the following to populate this variable:

Code: Select all

$opts = getopt('f:');

$auth = $opts['f'];
You could then run the script like this:

Code: Select all

/usr/bin/php /path/to/my/script.php -f test
Mr Sweg
New to forums
New to forums
Posts: 5
Joined: Tue May 27, 2014 9:51 am

Re: Cronjob problem...

Post by Mr Sweg »

I love how stupid I am at times ;-;

NVM, didn't read your post fully >_>
Thanks!
Post Reply