Re: Crack the Safe
I didn't think the coding on either one was great, so I recoded it, nothing is great... Just a quick recode so not the best it could be..
All credits go to carlg
<?php
include_once ('globals.php');
echo '<h3>Guess The Code</h3>';
if ($ir['guess'] >= 10) {
echo '<p style="color: #FF0000;">Error!</p><p style="color: #FF0000;">You have already attempted this 10 times.</p>';
die($h->endpage());
}
if (isset($_POST['n1'])) {
if (!ctype_digit($_POST['n1']) || !ctype_digit($_POST['n2']) || !ctype_digit($_POST['n3']) || !ctype_digit($_POST['n4'])) {
$_SESSION['Error'] = 'You have inputted an invalid character.';
die(header('Location: guess.php'));
}
if (strlen($_POST['n1']) != 1 || strlen($_POST['n2']) != 1 || strlen($_POST['n3']) != 1 || strlen($_POST['n4']) != 1) {
$_SESSION['Error'] = 'You number is an invalid one.';
die(header('Location: guess.php'));
}
$Join = $_POST['n1'] . $_POST['n2'] . $_POST['n3'] . $_POST['n4'];
$Code = mt_rand(1000, 9999);
//$Code = 1337; // Want the code to stay fixed? Add you code here.
if ($Join == $Code) {
$db->query("UPDATE `users` SET `money`=`money`+1200000 WHERE `userid`=".$userid);
$db->query("UPDATE `users` SET `guess`=`guess`+1 WHERE `userid`=".$userid);
$_SESSION['Success'] = 'Congrats! You success guessed the correct number!';
} else {
$_SESSION['Error'] = 'Sorry, you guessed wrong, please try again.';
$db->query("UPDATE `users` SET `guess`=`guess`+1 WHERE `userid`=".$userid);
}
$db->query("SELECT `guess` FROM `users` WHERE `userid`=".$ir['userid']);
if (isset($_SESSION['Success'])) {
echo '<p style="color: #0D961F;">',$_SESSION['Success'],'</p>';
unset($_SESSION['Success']);
}
if (isset($_SESSION['Error'])) {
echo '<p style="color: #FF0000;">',$_SESSION['Error'],'</p>';
unset($_SESSION['Error']);
}
echo 'Do you thing you are lucky enough to guess this code.
If you guess the code correctly you shall win $1,200,000 dollars just for guessing 4 numbers correctly!
You have used ',$ir['guess'],' of 10 guesses
<form action="guess.php" method="post">';
foreach (array('n1', 'n2', 'n3', 'n4') as $Name) {
echo '<select name="',$Name,'">';
for ($i=1; $i<10; ++$i) {
echo '<option value="',$i,'">',$i,'</option>';
}
echo '</select>';
}
echo '<input type="submit" value="Submit" />
</form>';
$h->endpage();
?>
Sql:
UPDATE `users` SET `guess` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0;
Cron:
$db->query("UPDATE `users` SET `guess`=0 WHERE `guess`>0");