Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbutv3/exercices/formular/

email.php
index.php
login.php
logout.php

index.php

86 lines ASCII Windows (CRLF)
<?php
session_start
();

$password $_SESSION['access'];

if (
$password != "123abc") {
    
header("Location: login.php");
    die();
}

$questions = [
    [
        
"question" => "What is question 2?",
        
"correctAnswer" => "What is the answer to question 1?",
        
"providedAnswer" => "",
    ],
    [
        
"question" => "What is the answer to question 1?",
        
"correctAnswer" => "What is the answer to question 1?",
        
"providedAnswer" => "",
    ],
    [
        
"question" => "What is the answer to...",
        
"correctAnswer" => "1",
        
"providedAnswer" => "",
    ]
];



if (isset(
$_POST["email"])) {
    
$answering true;

    for (
$i 0$i count($questions); $i++) {
        if (!isset(
$_POST["a" $i])) {
            
$answering false;
            break;
        }
        
$questions[$i]["providedAnswer"] = $_POST["a" $i];
    }

    if (
$answering) {
        
ob_start();
        include 
'email.php';
        
$output ob_get_clean();
        
$headers['MIME-Version'] = 'MIME-Version: 1.0';
        
$headers['Content-type'] = 'text/html; charset=iso-8859-1';
        
mail($_POST["email"], "form"$output$headers);
    }
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form method="POST">


        <?php for ($i 0$i count($questions); $i++) {
            
$question $questions[$i];
            
?>
            <p><?php echo $question["question"?></p>
            <input name="a<?php echo $i ?>" type="text">
        <?php ?>


        <p>Email</p>
        <input name="email" type="text">
        <button>Answer</button>
    </form>

    <form action="logout.php">
        <button>Logout</button>
    </form>
</body>

</html>

<?php ?>