Webbserverprogrammering 1

Show sourcecode

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

webbsrvprg/exercises/ovning7/

dininloggningssida.php
index.html
ovn_cook1.php
ovn_cook2.php
ovn_cook3.php
ovn_cook4.php
ovn_cook5.php

ovn_cook5.php

204 lines UTF-8 Windows (CRLF)
<?php
error_reporting
(-1); // Report all type of errors
ini_set('display_errors'1); // Display all errors 
ini_set('output_buffering'0); // Do not buffer outputs, write directly
session_start();
?>
<!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" action="">
        <?php if(count($_POST) == 0) { ?>
            <label for="name">Namn</label><br>
            <input type="text" name="name"> <br>
            <label for="epost">Email</label><br>
            <input type="email" name="epost"> <br>
            <label for="pw">Lösenord</label><br>
            <input type="password" name="pw"> <br>
            <input type="submit" value="Skicka">
        <?php 
        if(isset(
$_POST["name"])) {
            
$_SESSION["name"] = $_POST["name"];
            
$_SESSION["epost"] = $_POST["epost"];
            
$_SESSION["pw"] = $_POST["pw"];
            if(
$_POST["pw"] !== "FCB"){
                echo 
"Fel lösenord! <br>";
                echo 
"<input type=\"submit\" value=\"Gå tillbaka\">";
            }
            else {
                
?>
        <fieldset>
            <legend>Vem är bästa fotbollspelaren någonsin?</legend>
            <div>
                <input type="radio" name="fraga1" value="Messi" id="">
                <label for="Messi">Lionel Andrés Messi</label>
            </div>
            <div>
                <input type="radio" name="fraga1" value="Penaldo" id="">
                <label for="Penaldo">Cristiano Penaldo</label>
            </div>
            <div>
                <input type="radio" name="fraga1" value="Akinfenwa" id="">
                <label for="Akinfenwa">Adebayo Akinfenwa</label>
            </div>
            <div>
                <input type="radio" name="fraga1" value="Lamine" id="">
                <label for="Lamine">Lamine Yamal</label>
            </div>
            <input type="submit" value="Skicka">
        </fieldset>
        <?php }} if(isset($_POST["fraga1"])) {
            
$_SESSION["fraga1"] = $_POST["fraga1"];
            
?>
            <fieldset id="fraga2">
                <legend>Vilket lag har flest CL-titlar?</legend>
                <div>
                    <input type="radio" name="fraga2" value="FCB" id="">
                    <label for="FCB">FC Barcelona</label>
                </div>
                <div>
                    <input type="radio" name="fraga2" value="Milan" id="">
                    <label for="Milan">AC Milan</label>
                </div>
                <div>
                    <input type="radio" name="fraga2" value="Real" id="">
                    <label for="Real">Real Madrid</label>
                </div>
                <div>
                    <input type="radio" name="fraga2" value="City" id="">
                    <label for="City">Manchester City</label>
                </div>
                <input type="submit" value="Skicka">
            </fieldset>
            <?php } if(isset($_POST["fraga2"])) {
                
$_SESSION["fraga2"] = $_POST["fraga2"];
                
?>
                <fieldset id="fraga3">
                    <legend>Vilket lag vann EM 2024?</legend>
                    <div>
                        <input type="radio" name="fraga3" value="England" id="">
                <label for="England">England</label>
            </div>
            <div>
                <input type="radio" name="fraga3" value="Frankrike" id="">
                <label for="Frankrike">Frankrike</label>
            </div>
            <div>
                <input type="radio" name="fraga3" value="Neder" id="">
                <label for="Neder">Nederländerna</label>
            </div>
            <div>
                <input type="radio" name="fraga3" value="Spanien" id="">
                <label for="Spanien">Spanien</label>
            </div>
            <input type="submit" value="Skicka">
        </fieldset>
        <?php }?>
        <br>
    </form>
    <?php
    
if (isset($_POST["fraga3"])) {
        
$_SESSION["fraga3"] = $_POST["fraga3"];
        
$namn $_SESSION["name"];
        
$svar1 $_SESSION["fraga1"];
        
$svar2 $_SESSION["fraga2"];
        
$svar3 $_SESSION["fraga3"];
        
$antalRatt 0;
        
$fraga1 ="Vem är bästa fotbollspelaren någonsin? <br>";
        
$option11 " Lionel Andrés Messi<br>";
        
$option12 "Cristiano Penaldo<br>";
        
$option13 "Adebayo Akinfenwa<br>";
        
$option14 "Lamine Yamal <br> <br>";
        
$fraga2 ="Vilket lag har flest CL-titlar? <br>";
        
$option21 " FC Barcelona<br>";
        
$option22 "AC Milan<br>";
        
$option23 "Real Madrid<br>";
        
$option24 "Manchester City <br><br>";
        
$fraga3 ="Vilket lag vann EM 2024? <br>";
        
$option31 " England<br>";
        
$option32 "Frankrike<br>";
        
$option33 "Nederländerna<br>";
        
$option34 "Spanien <br>";
        switch (
$svar1) {
            case 
"Messi":
              
$antalRatt += 1;
              
$option11 "<span style=\"color:green\">Lionel Andrés Messi<br></span>";
              break;
            case 
"Penaldo":
                
$option12 "<span style=\"color:red\">Cristiano Penaldo<br></span>";
                break;
            case 
"Akinfenwa":
                
$option13 "<span style=\"color:red\">Adebayo Akinfenwa<br></span>";
                break;
            case 
"Lamine":
                
$option14 "<span style=\"color:red\">Lamine Yamal<br></span>";
                break;
          }
          switch (
$svar2) {
            case 
"Real":
              
$antalRatt += 1;
              
$option23 "<span style=\"color:green\">Real Madrid<br></span>";
              break;
            case 
"Milan":
                
$option22 "<span style=\"color:red\">AC Milan<br></span>";
                break;
            case 
"FCB":
                
$option21 "<span style=\"color:red\">FC Barcelona<br></span>";
                break;
            case 
"City":
                
$option24 "<span style=\"color:red\">Manchester City<br><br></span>";
                break;
          }
          switch (
$svar3) {
            case 
"Spanien":
              
$antalRatt += 1;
              
$option34 "<span style=\"color:green\">Spanien<br><br></span>";
              break;
            case 
"England":
                
$option31 "<span style=\"color:red\">England<br></span>";
                break;
            case 
"Frankrike":
                
$option32 "<span style=\"color:red\">Frankrike<br></span>";
                break;
            case 
"Neder":
                
$option34 "<span style=\"color:red\">Nederländerna<br></span>";
                break;
          }
        
$meddelande "Hej "$namn"! <br>""Du hade "$antalRatt" av 3 rätt <br> <br>"
        
.$fraga1
        
.$option11
        
.$option12
        
.$option13
        
.$option14
        
.$fraga2
        
.$option21
        
.$option22
        
.$option23
        
.$option24
        
.$fraga3
        
.$option31
        
.$option32
        
.$option33
        
.$option34
        
;

        

        
$mottagare=$_SESSION["epost"];
        
$rubrik="Resultat på Quiz";
        
$mejlhuvud="From: ".$_SESSION["epost"]." \nReply-To: danieleh@varmdogymnasium.se";
        
mail($mottagare$rubrik$meddelande$mejlhuvud);
        echo 
"<p>SKICKAT till ".$_SESSION["epost"]."</p>";
        echo 
"<p>================================</p>";
    }
    
?>
</body>

</html>