Jump to content
MakeWebGames

Help with getting my Cron to work?


-BRAIDZ-

Recommended Posts

This is a Cron I have for my lottery, and it returns a blank page, and does add an even and the lottery pot stays the same, any help would be great thanks!

Where am I screwing up?

 

<?php
include ("./config.php");
global $_CONFIG;
if($_GET['code'] != $_CONFIG['code']) { die(""); }
define("MONO_ON", 1);
require "class/class_db_{$_CONFIG['driver']}.php";
$db=new database;
$db->configure($_CONFIG['hostname'],
$_CONFIG['username'],
$_CONFIG['password'],
$_CONFIG['database'],
$_CONFIG['persistent']);
$db->connect();
$c=$db->connection_id;
include("./global_func.php");

$lotteryDetails = mysql_query("SELECT * FROM lotteryDetails");
$ld = mysql_fetch_assoc($lotteryDetails);

$winNumbers = array();
for($i = 0; $i < 6; $i++) {
   $num = mt_rand(1,46);
   if(empty($winNumbers)) {
       array_push($winNumbers, $num);
   }
   else {
       while(in_array($num, $winNumbers)) {
           $num = mt_rand(1,46);
       }
       array_push($winNumbers, $num);
   }
}
sort($winNumbers);
$wn = implode(",", $winNumbers);

$getTickets = mysql_query("SELECT * FROM lotterytickets");
$jackpot = (mysql_num_rows($getTickets) * $ld['lotprice']) + $ld['lotjackpot'];
$zero = 0; $one = 0; $two = 0; $three = 0;
$four = 0; $five = 0; $six = 0;
$users = array();
while($gt = mysql_fetch_assoc($getTickets)) {
   $yourNumbers = explode(",", $gt['numbers']);
   sort($yourNumbers);
   $uID = abs(@intval($gt['userid']));

   if(empty($users)) {
       array_push($users, $uID);
   }
   else {
       if(!in_array($uID, $users)) {
           array_push($users, $uID);
       }
   }

   $correct = 0;
   foreach($yourNumbers as $yn) {
       if(in_array($yn, $winNumbers)) {
           $correct++;
       }
   }

   if($correct == 0) { $zero++; }
   if($correct == 1) { $one++; }
   if($correct == 2) { $two++; }
   if($correct == 3) { $three++; }
   if($correct == 4) { $four++; }
   if($correct == 5) { $five++; }
   if($correct == 6) { $six++; }

   $updateTicket = ("UPDATE lotterytickets SET correct = ". abs(@intval($correct)) ." WHERE id = ". abs(@intval($gt['id'])) ."");
   mysql_query($updateTicket) OR die("Could not update ticket ID ". $gt['id'] .": ". mysql_error());
}

$potWin = array();
$countUsers = count($users);
if(!empty($users)) {
   for($ui = 0; $ui < $countUsers; $ui++) {
       $selectCorrect = mysql_query("SELECT correct, id, userid, numbers FROM lotterytickets WHERE userid = ". abs(@intval($users[$ui])) ."");
       $event = "<b><u>The winning numbers are: ". $wn .".</u></b>";
       $event .= "
The results from your ". abs(@intval(mysql_num_rows($selectCorrect))) ." lottery tickets:";
       $nowin = array(0,1,2);
       $total = 0;
       while($sc = mysql_fetch_assoc($selectCorrect)) {
           $event .= "
<b>Ticket numbers: ". mysql_real_escape_string($sc['numbers']) ."</b>";
           if(in_array($sc['correct'], $nowin)) {
               $event .= "<i> -- ". $sc['correct'] ." matching number(s) (no winnings)</i>";
           }
           else {
               if($sc['correct'] == 3) { $winnings = ($ld['lotprice'] + (floor($ld['lotprice'] * 0.5))); }
               if($sc['correct'] == 4) { $winnings = ($ld['lotprice'] + (floor($ld['lotprice'] * 0.8))); }
               if($sc['correct'] == 5) { $winnings = ($ld['lotprice'] + (floor($ld['lotprice'] * 1.4))); }
               if($sc['correct'] == 6) { $winnings = ($ld['lotprice'] + (floor($jackpot/$six))); array_push($potWin, $users[$ui]); }
               $event .= "<i> -- ". $sc['correct'] ." matching numbers (Won \$". number_format($winnings) .")</i>";
               $total += $winnings;
           }
       }
       $event .= "
You won a total of \$". number_format($total) .".<hr />";
       $subevent = mysql_real_escape_string(trim($event));
       event_add($users[$ui], $subevent);
       $giveWinnings = ("UPDATE users SET money = money + ". abs(@intval($total)) ." WHERE userid = ". abs(@intval($users[$ui])) ."");
       mysql_query($giveWinnings) OR die("Could not give userid ". $ui ." money: ". mysql_error());
   }
   if(!empty($potWin)) { $winners = implode(",", $potWin); }
   elseif(empty($potWin)) { $winners = "NA"; }
   $insertDone = ("INSERT INTO lotterydone (ldID, ldNUMBERS, ldZERO, ldONE, ldTWO, ldTHREE, ldFOUR, ldFIVE, ldSIX, ldPOT, ldPOTWIN, ldTIME) VALUES('','". $wn ."', ". $zero .", ". $one .", ". $two .", ". $three .", ". $four .", ". $five .", ". $six .", ". $jackpot .", '". $winners ."', UNIX_TIMESTAMP())");
   mysql_query($insertDone) OR die("Could not insert into lottery done: ". mysql_error());

   if($six == 0) {
       $jp = $jackpot;
   }
   elseif($six > 0) {
       $jp = 0;
   }
   $updateJackpot = ("UPDATE lotteryDetails SET lotjackpot = ". abs(@intval($jp)) ."");
   mysql_query($updateJackpot) OR die("Could not update jackpot: ". mysql_error());
}
else {
   event_add(1, "No lottery this week. <img src="images/smilies/frown.png" border="0" alt="" title="Frown" class="inlineimg" />");
}

$truncate = ("TRUNCATE TABLE lotterytickets");
mysql_query($truncate) OR die("Could not truncate: ". mysql_error());
?>

 

- - - Updated - - -

Here is the lottery mod

<?php
include_once(DIRNAME(__FILE__) ."/globals.php");
?>
<script language = "javascript" type = "text/javascript">
   var ticked = new Array();
   function tickBox(val) {
       var theid = "id" + val;
       if(document.getElementById(theid).checked == true) {
           ticked.push(theid);
       }
       else if(document.getElementById(theid).checked == false) {
           for(var sp = 0; sp < ticked.length; sp++) {
               if(ticked[sp] == theid) {
                   ticked.splice(sp,1);
               }
           }
       }
       if(ticked.length >= 6) {
           for(var count = 1; count < 47; count++) {
               var countID = "id" + count;
               if(document.getElementById(countID).checked == false) {
                   document.getElementById(countID).disabled = true;
               }
               document.getElementById("submit").disabled = false;
           }
       }
       else if(ticked.length < 6) {
           for(var count = 1; count < 47; count++) {
               var countID = "id" + count;
               document.getElementById(countID).disabled = false;
           }
           document.getElementById("submit").disabled = true;
       }
   }
   function formReset() {
       for(var n = 1; n < 47; n++) {
           var id = "id" + n;
           document.getElementById(id).checked = false;
           document.getElementById(id).disabled = false;
       }
       document.getElementById("dip").disabled = false;
       document.getElementById("submit").disabled = true;
       document.getElementById("luckysub").checked = false;
       document.getElementById("hiddenNums").value = "";
       ticked.splice(0,ticked.length);
   }
   function luckyDip() {
       var luckyarr = new Array();
       for(var d = 1; d < 47; d++) {
           var did = "id" + d;
           document.getElementById(did).checked = false;
           document.getElementById(did).disabled = true;
       }
       for(var c = 1; c < 7; c++) {
           var box = Math.floor((46)*Math.random()) + 1;
           var boxid = "id" + box;
           if(document.getElementById(boxid).checked == false) {
               document.getElementById(boxid).checked = true;
               luckyarr.push(box);
           }
           else {
               box = Math.floor((46)*Math.random()) + 1;
               boxid = "id" + box;
               while(document.getElementById(boxid).checked == true) {
                   box = Math.floor((46)*Math.random()) + 1;
                   boxid = "id" + box;
               }
               document.getElementById(boxid).checked = true;
               luckyarr.push(box);
           }
       }
       document.getElementById("dip").disabled = true;
       document.getElementById("luckysub").checked = true;
       document.getElementById("submit").disabled = false;
       document.getElementById("hiddenNums").value = luckyarr;
   }
</script>
<style type = "text/css">
.lotnum {
   width: 100%;
   text-align: center;
   font-size: 10px;
}
.luckdip {
   background-color: #E66C2C;
   color: #000000;
}
.odd {
   background-color: #306EFF;
}
.even {
   background-color: #4AA02C;
}
#bought {
   font-size: 20px;
   font-weight: bold;
   font-variant: small-caps;
}
</style>
<?php
$lotteryDetails = mysql_query("SELECT * FROM lotteryDetails");
$lD = mysql_fetch_object($lotteryDetails);
define('TICKETCOST', $lD->lotprice=10000);
define('LIMIT', $lD->lotlimit=50000);

if(!$_POST['submit']) {
   $all = mysql_query("SELECT id FROM lotterytickets");
   $numall = mysql_num_rows($all);
   $jackpot = ($numall * TICKETCOST) + $lD->lotjackpot;
   $yourTicks = mysql_query("SELECT id FROM lotterytickets WHERE userid = ". abs(@intval($ir['userid'])) ."");
   $numYourTicks = mysql_num_rows($yourTicks);
   print "<div align = 'center'>";
       print "<div class='generalinfo_txt'>
<div><img src='images/info_left.jpg' alt='' /></div>
<div class='info_mid'><h2 style='padding-top:10px;'> Lottery </h2></div>
<div><img src='images/info_right.jpg' alt='' /></div> </div>
<div class='generalinfo_simple'><br> <br><br>

It will cost you \$". number_format(TICKETCOST) ." to buy one lottery ticket, and you can only have ". number_format(LIMIT) ." tickets at any one time.</p>";
       $grammar = ($numYourTicks != 1) ? "tickets" : "ticket";
       print "You currently have ". number_format($numYourTicks) ." ". $grammar .".</p>";
       print "

The current jackpot is at \$". number_format($jackpot) .".</p>";
       print "

Select 6 numbers from below or click on Lucky Dip to have them randomly chosen for you!</p>";
       print "<form action = 'lottery.php' method = 'POST' name = 'boxes'>";
       print "<table class = 'lotnum'>";
       $rows = 0;
       $value = 1;
       while($rows <= 10) {
           print "<tr>";
           $cols = 0;
           while($cols <= 4) {
               $colclass = $cols+1;
               $class = ($value % 2 == 0) ? "even" : "odd";
               if($value <= 46) {
                   $id = "id".$value;
                   print "<td class = '". $class ."'>". $value ."  <input type = 'checkbox' name = 'numbers[]' id = '". $id ."' value = '". $value ."' onClick = \"tickBox(this.value);\" /></td>";
                   $value++;
                   $cols++;
               }
               else { $cols++; }
           }
           print "</tr>";
           $rows++;
       }
       print "
       <tr>
           <td><input type = 'button' name = 'lucky' id = 'dip' value = 'Lucky Dip' onClick = \"luckyDip();\" /></td>
           <td><input type = 'button' name = 'resetForm' id = 'resetForm' value = 'Reset' onClick = \"formReset();\" /></td>
           <td colspan = '2'><input type = 'submit' name = 'submit' id = 'submit' value = 'Buy Ticket' disabled = 'disabled' /></td>
           <td class = 'luckdip'>Lucky Dip<input type = 'checkbox' name = 'luckysub' value = 'lucky' id = 'luckysub' disabled = 'disabled' /></td>
       </tr>";
       print "</table>
       <input type = 'hidden' id = 'hiddenNums' name = 'hiddenNums' value = '' />
       </form>";
   print "</div>";
}
else {
   $tickets = mysql_query("SELECT userid FROM lotterytickets WHERE userid = ". abs(@intval($ir['userid'])) ."");
   if($_POST['hiddenNums'] == '') {
       $countNums = count($_POST['numbers']);
       $numbers = $_POST['numbers'];
       $lucky = "";
       $dip = 0;
   }
   elseif($_POST['hiddenNums'] != '') {
       $explode = explode(",",$_POST['hiddenNums']);
       $countNums = count($explode);
       $numbers = $explode;
       $lucky = "Lucky Dip";
       $dip = 1;
   }

   if($countNums != 6 || empty($numbers)) {
       print "

You either didn't select any numbers or you didn't select 6 numbers.</p>


<a href = 'lottery.php'>Back</a></p>";
   }
   elseif($ir['money'] < TICKETCOST) {
       print "

You need to have \$". number_format(TICKETCOST) ." to buy a lottery ticket.</p>


<a href = 'lottery.php'>Back</a></p>";
   }
   elseif(mysql_num_rows($tickets) >= LIMIT) {
       print "

You can only have ". number_format(LIMIT) ." lottery tickets at once.</p>


<a href = 'lottery.php'>Back</a></p>";
   }
   else {
       sort($numbers);
       $punct = 0;
       $store = "";
       print "<p id = 'bought'>Ticket bought!</p>";
       print "

Your ". $lucky ." numbers are: ";
       for($i = 0; $i < $countNums; $i++) {
           $n = abs(@intval($numbers[$i]));
           if($punct == 5) { $ender = "."; $store .= $n; }
           else { $ender = ", "; $store .= $n .","; }
           print $n . $ender;
           $punct++;
       }
       print "</p>";
       print "

<a href = 'lottery.php'>Back</a></p>";

       $insertTicket = ("INSERT INTO lotterytickets (id, userid, numbers, bought, luckydip) VALUES('',". abs(@intval($ir['userid'])) .", '". mysql_real_escape_string($store) ."', UNIX_TIMESTAMP(), ". abs(@intval($dip)) .")");
       mysql_query($insertTicket) OR die("Could not insert ticket: ". mysql_error());

       $takeMoney = ("UPDATE users SET money = money - ". abs(@intval(TICKETCOST)) ." WHERE userid = ". abs(@intval($ir['userid'])) ."");
       mysql_query($takeMoney) OR die("Could not take money: ". mysql_error());
   }
}

$h->endpage();
?>
Link to comment
Share on other sites

It's supposed to return blank, nothing is being printed to the user.

Also, make sure your cron is setup to use the correct path (and code). Normally something like:

* * * * 0 curl yoursite.tld/path/to/lottery_cron.php?code=THE_CODE_FROM_YOUR_CONFIG.PHP_FILE

Note: it could do with converting to v2

I'll do the cron file for you. You may wish to use this topic to help you if you're not sure on how to do it

lottery_cron.php

<?php
include "./config.php";
global $_CONFIG;
if($_GET['code'] != $_CONFIG['code']) {
die("");
}
define("MONO_ON", 1);
require "class/class_db_{$_CONFIG['driver']}.php";
$db = new database;
$db->configure($_CONFIG['hostname'], $_CONFIG['username'], $_CONFIG['password'], $_CONFIG['database'], $_CONFIG['persistent']);
$db->connect();
$c = $db->connection_id;
include "./global_func.php";
$lotteryDetails = $db->query("SELECT * FROM lotteryDetails");
$ld             = $db->fetch_row($lotteryDetails);
$winNumbers     = array();
for($i = 0; $i < 6; $i++) {
$num = mt_rand(1, 46);
if(empty($winNumbers))
	array_push($winNumbers, $num);
else {
	while(in_array($num, $winNumbers))
		$num = mt_rand(1, 46);
	array_push($winNumbers, $num);
}
}
sort($winNumbers);
$wn         = implode(",", $winNumbers);
$getTickets = $db->query("SELECT * FROM lotterytickets");
$jackpot    = $db->num_rows($getTickets) * $ld['lotprice'] + $ld['lotjackpot'];
$zero       = 0;
$one        = 0;
$two        = 0;
$three      = 0;
$four       = 0;
$five       = 0;
$six        = 0;
$users      = array();
while($gt = $db->fetch_row($getTickets)) {
$yourNumbers = explode(",", $gt['numbers']);
sort($yourNumbers);
if(empty($users))
	array_push($users, $gt['userid']);
else {
	if(!in_array($gt['userid'], $users))
		array_push($users, $gt['userid']);
}
$correct = 0;
foreach($yourNumbers as $yn)
	if(in_array($yn, $winNumbers))
		++$correct;
if($correct == 0)
	++$zero;
if($correct == 1)
	++$one;
if($correct == 2)
	++$two;
if($correct == 3)
	++$three;
if($correct == 4)
	++$four;
if($correct == 5)
	++$five;
if($correct == 6)
	++$six;
$db->query("UPDATE lotterytickets SET correct = " . $correct . "  WHERE id = " . $gt['id']);
}
$potWin     = array();
$countUsers = count($users);
if(!empty($users)) {
for($ui = 0; $ui < $countUsers; $ui++) {
	$selectCorrect = $db->query("SELECT correct, id, userid, numbers FROM lotterytickets WHERE userid = " . $users[$ui]);
	$event         = "<b><u>The winning numbers are: " . $wn . ".</u></b><br />";
	$event .= "The results from your " . abs(@intval($db->num_rows($selectCorrect))) . " lottery tickets:<br />";
	$nowin = array(
		0,
		1,
		2
	);
	$total = 0;
	while($sc = $db->fetch_row($selectCorrect)) {
		$event .= "<b>Ticket numbers: " . $sc['numbers'] . "</b>";
		if(in_array($sc['correct'], $nowin))
			$event .= "<i> -- " . $sc['correct'] . " matching number(s) (no winnings)</i>";
		else {
			if($sc['correct'] == 3)
				$winnings = $ld['lotprice'] + floor($ld['lotprice'] * 0.5);
			if($sc['correct'] == 4)
				$winnings = $ld['lotprice'] + floor($ld['lotprice'] * 0.8);
			if($sc['correct'] == 5)
				$winnings = $ld['lotprice'] + floor($ld['lotprice'] * 1.4);
			if($sc['correct'] == 6) {
				$winnings = $ld['lotprice'] + floor($jackpot / $six);
				array_push($potWin, $users[$ui]);
			}
			$event .= "<i> -- " . $sc['correct'] . " matching numbers (Won \$" . number_format($winnings) . ")</i>";
			$total += $winnings;
		}
	}
	$event .= "You won a total of \$" . number_format($total) . ".<hr />";
	event_add($users[$ui], trim($event));
	$db->query("UPDATE users SET money = money + " . $total . " WHERE userid = " . $users[$ui]);
}
$winners = !empty($potWin) ? implode(",", $potWin) : 'N/A';
$db->query("INSERT INTO lotterydone (ldID, ldNUMBERS, ldZERO, ldONE, ldTWO, ldTHREE, ldFOUR, ldFIVE, ldSIX, ldPOT, ldPOTWIN, ldTIME) VALUES('','" . $wn . "', " . $zero . ", " . $one . ", " . $two . ", " . $three . ", " . $four . ", " . $five . ", " . $six . ", " . $jackpot . ", '" . $winners . "', UNIX_TIMESTAMP())");
$jp = !$six ? $jackpot : 0;
$db->query("UPDATE lotteryDetails SET lotjackpot = " . $jp);
} else
event_add(1, "No lottery this week. :(");
$db->query("TRUNCATE TABLE lotterytickets");
Edited by Magictallguy
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...