Hádanie náhodného čísla v PHP
<?php /** * @author sczdavos * @site www.itnetwork.cz */ header('Content-type: text/html; charset=utf8'); if ((isset($_POST['number'])) && ($_POST['number'])) $number = $_POST['number']; else $number = rand(0, 200); $tries = 0; if (isset($_POST['user_number'])) { $tip = $_POST['user_number']; $tries = $_POST['tries'] + 1; $diff = abs($tip - $number); if ($diff > 50) echo('Hodně vedle'); else if (($diff <= 50) && ($diff >= 21)) echo('Vedle'); else if (($diff <= 20) && ($diff >= 6)) echo('Přihořívá'); else if (($diff <= 5) && ($diff >= 1)) echo('Těsně vedle'); else echo('Trefa'); echo('Pokus číslo: ' . $tries); } echo(' <form method="post"> <input type="hidden" name="number" value="' . $number . '" /> <input type="hidden" name="tries" value="' . $tries . '" /> <input type="text" name="user_number" /> <input type="submit" /> </form> ');