Webbserverprogrammering 1

Show sourcecode

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

webbsrvprg/quiz/

admin.php
createQuiz.php
createadmin.php
logIn.php
myStats.php
playquiz.php
result.php
scoreboard.php
signIn.php
start.php
startsida.php
stats.php
style.css
tables.php
update.php

start.php

45 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>Quiz</title>
  
  <link rel="stylesheet" href="style.css" title="General stylesheet">
</head>
<body>
  <?php
  
// Om man tryckt på "logga ut"-knappen, ränsa alla cookies och omdirigera till inloggningssidan.
  
if (isset($_POST["logOut"])) {
    
$time time() - 1;

    
setcookie("id"""$time);
    
setcookie("username"""$time);
    
setcookie("password"""$time);
    
setcookie("type"""$time);

    
header("location: logIn.php");
  }
?>

<header>
<?php
  
if (isset($_COOKIE["id"]) && isset($_COOKIE["username"]) && isset($_COOKIE["password"]) && isset($_COOKIE["type"])) {
    
// Skriv ut användarens namn i headern
    
echo "<p>Hej "$_COOKIE["username"] . "!</p>";

    
// Lägg till en länk till admin-sidan om användaren är en admin
    
if ($_COOKIE["type"] == "admin") {
      echo 
"<a href='admin.php'>Admin</a>";
    }
  } else {
    
// Omdirigera till inloggningssidan om användaren inte är inloggad(inga cookies finns)
    // header("location: logIn.php");
  
}

  include (
'../dbconnection.php');
  
?>

  <!-- Knapp för att logga ut -->
  <form method="post"><input type="submit" name="logOut" value="Logga ut"></form>
  </header>