phpformsgetcredits

php slot machine credits


Hey iam making a slot machine and is almost done. The only thing i need is the credit's to stay so it just add points on the credit's. Like if i have 100 credits and then get 25 credits i want it to say 125 credits. Now i don't know how to get the credits from the round before.
This is what i got:

            <?
    $tal = rand (1,3 ); {
    echo "<img src='css/billeder/enarmet$tal.gif' class=billed />"; 
    $tal2 = rand (1,3 ); 
    echo "<img src='css/billeder/enarmet$tal2.gif' class=billed />"; 
    $tal3 = rand (1,3 ); 
    echo "<img src='css/billeder/enarmet$tal3.gif' class=billed />"; }
    ?>
            </div>
            <div id="credits">
                <h3 id="credits2">CREDITS</h3>
                <h3 id="credits3"><?php 
                $credits=$_GET['credits'];
        if ($tal . $tal2 . $tal3 == 111){
            ($credits=($credits+100));              
        }
        if ($tal . $tal2 . $tal3 == 222){
            ($credits=($credits+50));                
        }
        if ($tal . $tal2 . $tal3 == 333){
            ($credits=($credits+25));               
        }
        echo $credits;
        ?></h3>
            </div>
        </div>
        <form action="index.php" method="POST">
            <input type="submit" value="SPIN" class="knap">
        </form> 
        <form action="cashout.php" method="POST">
            <input type="submit" value="CASH OUT" class="knap">
        </form>
    </div>

Solution

  • What about using sessions? Store and retrieve credits from session storage using

    session_start();
    $credits = $_SESSION['credits'];
    

    at the top of your script and

    $_SESSION['credits'] = $credits;
    

    at the bottom.

    This way credits will be preserved between page-loads.