I'm learning web development and I'm creating a puzzle website where the home page will only have an answer input and will redirect the user to the next puzzle based on the answer. E.g. solved the first level and the answer is "solution". When typing "solution" the user will be redirected to the second level.
But it's important that the user can only access the second level page with the password, otherwise it won't allow.
I have a super basic draft that correctly redirects the user based on the answer, but I don't know how to proper restrict direct access to the next levels.
Home page input:
<form method="post" action="validation.php">
Answer: <input type="text" name="answer">
<input type="submit">
</form>
validation.php:
<?php
$input = $_POST["answer"];
if ($input == "correct answer 1") {
header("Location: /levels/level2/level2.php"); }
if ($input == "correct answer 2") {
header("Location: /levels/level3/level3.php"); }
if ($input == "correct answer 3") {
header("Location: /levels/level4/level4.php"); }
?>
The order of the answers is irrelevant; if the user enters the password for level 7 without first going through the previous levels, he should be taken to level 7. I'm also not overly concerned about safety; all I want to do is play a game with some friends. I believe there is a way to do this with PHP and JS, but any solution that works is fine.