function generateWord($wordlist) { $num = rand(0, count($wordlist) - 1); if (count($wordlist) == count($_SESSION['words_asked'])) { //something... unset($_SESSION['last_word']); echo 'You\'ve seen all the words! <form><button type="button" onclick="window.location=\'?new=1\'">Start new session (words in English).</button><button type="button" onclick="window.location=\'?new=1&german=1\'">Start new session (words in German).</button></form>'; echo '<h1>Statistics</h1>'; echo '<div id="mainstats"> <table> <tr> <td>Correctly guessed words:</td> <td>' . count($_SESSION['words_correct']) . '</td> <td><button type="button" onclick="javascript:showCorrect()">Show</button></td> </tr> <tr class="ans" id="ans-correct" style="background-color:#96FFA3; padding: 5px"> <td colspan="3"> '; foreach ($_SESSION['words_correct'] as $w) { echo $wordlist[$w]['english'] . '<br>'; } echo ' </td> </tr> <tr> <td>Incorrectly guessed words:</td> <td>' . count($_SESSION['words_incorrect']) . '</td> <td><button type="button" onclick="javascript:showIncorrect()">Show</button></td> </tr> <tr class="ans" id="ans-incorrect" style="background-color:#FF9696; padding: 5px"> <td colspan="3"> '; foreach ($_SESSION['words_incorrect'] as $w) { echo $wordlist[$w]['english'] . '<br>'; } echo ' </td> </tr> <tr> <td>Words without answer:</td> <td>' . count($_SESSION['words_unanswered']) . '</td> <td><button type="button" onclick="javascript:showUnanswered()">Show</button></td> </tr> <tr class="ans" id="ans-unanswered" style="background-color:#FFE976; padding: 5px"> <td colspan="3"> '; foreach ($_SESSION['words_unanswered'] as $w) { echo $wordlist[$w]['english'] . '<br>'; } echo ' </td> </tr> </table> </div>'; } else { if (in_array($num, $_SESSION['words_asked'])) { generateWord($wordlist); } else { $_SESSION['last_word'] = $num; array_push($_SESSION['words_asked'], $num); echo 'Your next word/phrase is: "' . $wordlist[$num]['english'] . '". <form><button onclick="javascript:showAnswer()" id="showlink" type="button">Guessed it? Show answer!</button></form><br> <div id="answer"> Possible translations: <ol> '; foreach ($wordlist[$num]['german'] as $m) { echo '<li>' . $m . '</li>'; } echo ' </ol> <form>Did you guess correctly? <button type="button" onclick="window.location=\'?g=1\'" style="color:green">Yes</button> <button type="button" onclick="window.location=\'?g=0\'" style="color:red">No</button></form> </div><br><br> Word ' . count($_SESSION['words_asked']) . ' of ' . count($wordlist) . '.<form><button type="button" onclick="window.location=\'' . $_SERVER['PHP_SELF'] . '\'">Next word (no answer!)</button><button type="button" onclick="window.location=\'?new=1\'">Start new session (words in English).</button><button type="button" onclick="window.location=\'?new=1&german=1\'">Start new session (words in German).</button></form> '; } } }
/** * Returns a password from the array $words that meets the criteria specified in * $options. */ function generatePassword($words, $options) { // form the password (words -> digits -> symbols) $password = ""; // append words to the password until the min_words and min_password_length // (account for length added by digits and symbols) criteria are met $i = 0; while ($i < $options["min_words"] || strlen($password) < $options["min_password_length"] - $options["num_digits"] - $options["num_symbols"]) { // append a separator if not the first word if ($i != 0) { $password .= $options["separator"]; } // append word $password .= generateWord($words, $options); // iterate to next word $i++; } // append num_digits digits to the password for ($i = 0; $i < $options["num_digits"]; $i++) { $password .= generateDigit(); } // append num_symbols symbols to the password for ($i = 0; $i < $options["num_symbols"]; $i++) { $password .= generateSymbol(); } return $password; }