Show sourcecode
The following files exists in this folder. Click to view.
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
logIn.php
60 lines UTF-8 Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Log In</title>
</head>
<body>
<?php
/** @var PDO $dbconn */
include ('../dbconnection.php');
if (isset($_GET["username"]) && isset($_GET["password"])) {
$name = htmlspecialchars($_GET["username"]);
$pwd = htmlspecialchars($_GET["password"]);
try {
// Kolla om kontoinformationen som skrevs in finns
$sql = "SELECT * FROM quizUsers WHERE username=? AND password=?";
$stmt = $dbconn->prepare($sql);
$data = array($name, $pwd);
$stmt->execute($data);
if ($res = $stmt->fetch(PDO::FETCH_ASSOC)) {
// Om kontot finns, spara dess information i ett dygn i cookies
$time = time() + 60 * 60 * 24;
setcookie("id", $res["id"], $time);
setcookie("username", $res["username"], $time);
setcookie("password", $res["password"], $time);
setcookie("type", $res["type"], $time);
// Dirigera till adminsidan om användaren är en admin, dirigera till startsidan annars
if ($res["type"] == "admin") {
header("location: admin.php");
} else {
header("location: startsida.php");
}
} else {
echo "Användarnamet eller lösenordet är fel, försök igen.";
}
}
catch (PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
}
?>
<!-- Inloggningsformulär -->
<form action="" method="get">
<input type="text" name="username" placeholder="Användarnamn"> <br>
<input type="password" name="password" placeholder="Lösenord"> <br>
<input type="submit" value="Logga in">
</form>
<p>Har du inget konto?<a href="signIn.php">Skapa ett</a></p>
</body>
</html>