Jump to content

[SOLVED] How to keep people from cheating?


pocobueno1388

Recommended Posts

Okay, I have just created a small game for a website I own that players may play. Basically the players guess which egg the dragon is in, and if they get it right there pot of money increases, if they get it wrong they lose and don't get any money.

 

The problem is that when they lose it takes them to a page that says, "You lose"...they can click the back button and still collect their money though, and I don't want them to be able to do this because if they lose they shouldn't get money. They can also click back and start the game where they left off...not good.

 

I made it so you guys can come and test the game out so you can get a feel of what I am talking about. <a href="http://dragon-dynasty.com/guesstheegg.php">Click Here</a>

 

Here is the code:

 


<?php
include 'config.php';

//If they want to quit and collect their money

   if ($_POST['quit']){
    $final_cash = $_POST['cash'];
    
    echo "Successfully collected $$final_cash";
    
    exit;
    }

//If they guess

if ($_POST['guess']){

$turn = $_POST['turn'];
$cash = $_POST['cash'];
$num = rand(1,3);
$next_turn = $turn + 1;

   if ($num == "2" || $num == "3"){
   
      switch ($turn){
      case 0:
         $increase = 100;
         break;
      case 1:
         $increase = 150;
         break;
      case 2:
         $increase = 200;
         break;
      case 3:
         $increase = 250;
         break;
      case 4:
         $increase = 300;
         break;
      case 5:
         $increase = 350;
         break;
      case 6:
         $increase = 400;
         break;
      case 7:
         $increase = 450;
         break;
      case 8:
         $increase = 500;
         break;
      case 9:
         $increase = 550;
         break;
      default:
         $increase = 1000;
      }
      
$next_increase = $increase + 50;
   
      if ($cash < 0){
         $cash = 0;
      } else {
         $cash += $increase;
         $turn++;
         $win = TRUE;
      }
   
      echo "Pot: $$cash<br>";
      echo "Turn: $turn<br>";
      echo "If you guess this one right, your pot will increase $$next_increase!<p>";
            
      
   } else {

//If they lose
   
      echo "<center>You lose =( <p> <img src='Etc/otherimages/guess2.gif'><p> <a href='guesstheegg.php'>Play again</a>";
      $cash = 0;
      $turn = 0;
      $win = FALSE;
      
   include 'footer.php';
   exit;
   }

//If they win

   if ($win == TRUE){
      echo "<center><img src='Etc/otherimages/guess3.gif'><br><h2>Correct!</h2>
            <p>
            <form method='post' action='{$_SERVER['PHP_SELF']}'>
            <input type='submit' name='quit' value='Collect your $$cash and quit the game.'>
            <input type='hidden' name='cash' value='$cash'>
            </form>";
   }
   
   
   
print<<<HERE

<p><center><table width=600 class=tstyle6><tr>
<td class=tstyle2><center> G u e s s - T h e - E g g  </td></tr><tr>
<td><center>
<table id=menue class=tstyle5 width="100%"><tr>
<td><center><font color=2A305A> <p></font></table id=topic></td></tr><tr><td><center><br>
<table class=tstyle1 width=500><tr align='center'>

<form method=post action"{$_SERVER['PHP_SELF']}">

<td height=50 width=60 class=tstyle5><INPUT TYPE="image" SRC="Etc/otherimages/guess1.gif" name="guess"></td>
<td width=60 class=tstyle5><INPUT TYPE="image" SRC="Etc/otherimages/guess1.gif" name="guess"></td>
<td width=60 class=tstyle5><INPUT TYPE="image" SRC="Etc/otherimages/guess1.gif" name="guess"></td>

</table></table><p>

<input type='hidden' name='cash' value="$cash">
<input type="hidden" value="$turn" name="turn">
<input type="hidden" value="2" name="guess">
</form>

HERE;
     
include 'footer.php';
exit;
}


//main display

print<<<HERE

<p><center><table width=600 class=tstyle6><tr>
<td class=tstyle2><center> G u e s s - T h e - E g g  </td></tr><tr>
<td><center>
<table id=menue class=tstyle5 width="100%"><tr>
<td><center><font color=2A305A> <p></font></table id=topic></td></tr><tr><td><center><br>
<table class=tstyle1 width=500><tr align='center'>

<form method="post" action"{$_SERVER['PHP_SELF']}">

<td height=50 width=60 class=tstyle5><INPUT TYPE="image" SRC="Etc/otherimages/guess1.gif"></td>
<td width=60 class=tstyle5><INPUT TYPE="image" SRC="Etc/otherimages/guess1.gif" ></td>
<td width=60 class=tstyle5><INPUT TYPE="image" SRC="Etc/otherimages/guess1.gif"></td>

</table></table><p>


<input type="hidden" value="0" name="cash">
<input type="hidden" value="0" name="turn">
<input type="hidden" value="2" name="guess">

</form>


HERE;

include 'footer.php';

?>

 

What determines if they win or not is a random number between 1 and 3. If the number is 2 or 3, they win. If not, they lose.

 

I know that is a lot of code to go through...but I'm not sure how else to give it to you because you basically need the whole thing.

 

I appreciate your help =D Thanks.

Link to comment
https://forums.phpfreaks.com/topic/39060-solved-how-to-keep-people-from-cheating/
Share on other sites

umm try using cookies

like when they win it sets a cookie

<?
$_SESSION['state'] = "win";
if($_SESSION['state'] == "win")
{
//collect money
$_SESSION['state'] = "blank";
}
if
if($_SESSION['state'] == "lost")
{
//no money
$_SESSION['state'] = "blank";
}
?>
etc..

.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.