我在index.php页面中间有以下HTML:
<form action="" method="post"><input type="submit" value="Reset Game" class="reset-button" title="Admitting defeat?"></form>
Run Code Online (Sandbox Code Playgroud)
在我的页面顶部,我有以下检查:
if (isset($_POST["submit"]) {
if ($_POST["submit"] === "Reset Game"] {
$_SESSION["word"] = generate_word("dictionary.txt");
$_SESSION["word-progress"] = turn_to_underscores($_SESSION["word"]);
}
}
Run Code Online (Sandbox Code Playgroud)
这为我的刽子手游戏以及强调版本生成了这个词.以下是这些功能:
/**
* Generate a random word from the given dictionary file
* @param $filename Name of the dictionary file
* @return Random word
*/
function generate_word($filename) {
$dictionary_file = new SplFileObject($filename);
$dictionary_file->seek(rand(0, 80367));
return trim($dictionary_file->current());
}
/**
* Accepts a word and returns it as underscores for obfuscation
* @param $word A given word
* @return Returns the word as underscores
*/
function turn_to_underscores($word) {
$underscored_word = "";
for ($i = 0; $i < strlen($word); $i++) {
$underscored_word .= "_";
}
return $underscored_word;
}
Run Code Online (Sandbox Code Playgroud)
我带来了一个require "functions.php";电话.
我究竟做错了什么?