Categories
Randomizers

Roll the Dice

Simple presentation of php random function – http://roll-the-dice.goodplace.eu
Page is simulation of dice rolling. 1 – 100 dices with values from 4 to 100.

How its made
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php
$DiceCount = $_POST["DiceCount"]; //1 to 100
$DiceMaxValue = $_POST["DiceMaxValue"]; // 4 to 100
if (!isset($_POST['submit'])) { // if page is not submitted to itself set default values
//
$DiceCount = 6;
$DiceMaxValue = 6;
}
?>
<html>
...
<form method="post" action="<?php echo $PHP_SELF;?>">
<table border="0">
<tr><td>Dice Count: </td><td><?php echo "<input type=\"text\" size=\"12\" maxlength=\"12\" name=\"DiceCount\" value=\"".$DiceCount."\">"?>1 - 100 <br /></td></tr>
<tr><td>Dice Max Value: </td><td><?php echo "<input type=\"text\" size=\"12\" maxlength=\"12\" name=\"DiceMaxValue\" value=\"".$DiceMaxValue."\">"?>4 - 100 <br /></td></tr>
</table>
<br />
<input type="submit" value="Roll !" name="submit">
</form>
<?php
if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
}
else {
//CHECK if input is correct
for ($i = 1; $i <= $DiceCount; $i++) {
echo "<font size=\"6\">".rand(1,$DiceMaxValue)."</font><br />";
}
}
?>
...

Leave a Reply