Datensatz Alter in Tagen | 3.094 |
ID | 44 |
Anlagedatum | 16.06.2015 [12:46] |
Überschrift | Simples Rechen-Kaptscha |
Kategorie | Codeschnipsel |
Filter | Alle |
Status | Stable |
Gesperrt | Nein |
Gehört | Matthias Nitzschke |
Gibt eine simple Rechenaufgabe als Abfrage in einem Formular aus. Ist die Lösung korrekt, kann gespeichert werden....
<?PHP session_start(); if(isset($_POST['save']) AND ($_POST['save'] == 'senden')) { if($_POST['kaptscha'] == $_SESSION['kaptscha']) { // Hier kann nun gespeichert werden.... echo '<pre>'; print_r($_POST); print_r($_SESSION['kaptscha']); echo '</pre>'; } } $kaptscha = ''; // kaptscha $wie = array('+','-','*'); $aufgabe = array('plus', 'minus','mal'); $w = rand(0,2); $a = rand(1,10); $b = rand(1,10); eval('$_SESSION[\'kaptscha\'] = '.$a."$wie[$w]".$b.';'); ?> <form method="post" action="<?PHP echo $_SERVER['SCRIPT_NAME']; ?>"> <div class="kap">Was ergibt <?PHP echo $a; ?> <?PHP echo $aufgabe[$w]; ?> <?PHP echo $b; ?></div> <input type="text" class="kaptscha" name="kaptscha" value="<?PHP echo $kaptscha; ?>"> <span class="error"><?PHP echo $error; ?></span> <div class="sendbttn"> <input type="submit" class="buttons" name="save" value="senden" /> </div> </form>