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_cook4.php

64 lines UTF-8 Windows (CRLF)
 <!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="">
         <input type="number" name="tal"><br>
         <br>
         <input type="submit" name="Submit">
     </form>
     <form action="" method="post">
         <input type="hidden" name="destroy" value="1">
         <input type="submit" name="Destroy" value="Destroy">
     </form>
 <?php

    session_start
();

    if (isset(
$_POST['destroy'])) {
        
$_SESSION = array();

        if (
ini_get("session.use_cookies")) {
            
$params session_get_cookie_params();
            
setcookie(
                
session_name(),
                
'',
                
time() - 42000,
                
$params["path"],
                
$params["domain"],
                
$params["secure"],
                
$params["httponly"]
            );
        }

        
session_destroy();
    }

    if (isset(
$_SESSION['visningar'])) {
        
$_SESSION['visningar']++;
    } else {
        
$_SESSION['visningar'] = 1;
    }

    if (isset(
$_POST['tal']) && !empty($_POST['tal'])) {
        
$talsumma 0;
        
$_SESSION['allanummer'][] = $_POST['tal'];
        echo 
"Tal: <br>";
        for (
$i 0$i count($_SESSION['allanummer']); $i++) {
            echo 
$_SESSION['allanummer'][$i] . "<br>";
            
$talsumma += $_SESSION['allanummer'][$i];
        }
        echo 
"<br> Medelvärde: "$talsumma/$_SESSION['visningar'];
    }


    
?>
 </body>

 </html>