Zelf dacht ik hierbij aan een array, maar ik weet dan weer niet hoe ik bijvoorbeeld een sessie in een array kan opslaan. Kunnen jullie me hierbij helpen?
index.php
<?php
session_start();
if($_SESSION["name"])
header("Location:play.php");
?>
<!DOCTYPE html>
<html>
<head>
<title>HogerLager</title>
<meta charset="UTF-8">
</head>
<body>
<h1>HogerLager</h1>
<h2>Voer uw naam in</h2>
<form action="play.php" method="POST">
<input type="text" name="name">
<input type="submit" name="savename" value="Spelen!">
</form>
</body>
</html>
play.php
<?php
session_start();
if($_POST["name"]&&!$_SESSION["name"])
$_SESSION["name"]=$_POST["name"];
elseif(!$_POST["name"]&&!$_SESSION["name"])
header("Location:index.php");
if(!$_SESSION["numb"])
$_SESSION["numb"]=rand(1,1000);
?>
<!DOCTYPE html>
<html>
<head>
<title>HogerLager</title>
<meta charset="UTF-8">
</head>
<body>
<h1>HogerLager</h1>
<h2>Kies een cijfer (van 1 tot 1000)</h2>
<h3>Now Playing: <?php echo $_SESSION["name"]; ?> | <a href="clear.php">Opnieuw</a></h3>
<h4>Status</h4>
<p><?php if($_POST["name"]){echo "Invoer speler: ".$_POST["name"]." | ";} ?>Sessie cijfer: <?php echo $_SESSION["numb"]; ?> | Sessie speler: <?php echo $_SESSION["name"]; ?></p>
<form action="try.php" method="POST">
<input type="text" name="value">
<input type="submit" name="savename" value="Spelen!">
</form>
</body>
</html>
try.php
<?php
session_start();
if(!$_SESSION["name"])
header("Location:index.php");
if(!$_SESSION["numb"])
header("Location:play.php");
if(!$_SESSION["try"])
$_SESSION["try"]=1;
else
$_SESSION["try"]=$_SESSION["try"]+1;
?>
<!DOCTYPE html>
<html>
<head>
<title>HogerLager</title>
<meta charset="UTF-8">
</head>
<body>
<h1>HogerLager</h1>
<h2>U raadde: <?php echo $_POST["value"]; ?> (poging <?php echo $_SESSION["try"]; ?>)</h2>
<?php
if(!$_POST["value"]){
$return="Voer een cijfer in. <a href=\"play.php\">Opnieuw</a>";
}elseif($_POST["value"]>$_SESSION["numb"]){
$return="Voer een lager cijfer in. <a href=\"play.php\">Opnieuw</a>";
}elseif($_POST["value"]<$_SESSION["numb"]){
$return="Voer een hoger cijfer in. <a href=\"play.php\">Opnieuw</a>";
}elseif($_POST["value"]==$_SESSION["numb"]){
if($_SESSION["try"]==1)
$try="poging";
else
$try="pogingen";
$return="GEFELICITEERD! U raadde ".$_SESSION["numb"]." in ".$_SESSION["try"]." ".$try.". <a href=\"highscores.php\">Highscores</a> | <a href=\"play.php\">Opnieuw</a>";
unset($_SESSION["numb"]);
unset($_SESSION["try"]);
}
?>
<h3><?php echo $return; ?></h3>
</body>
</html>
clear.php
<?php
session_start();
unset($_SESSION["name"]);
header("Location:index.php");
?>