Basically finished this simulation

This commit is contained in:
Bildcraft1 2024-11-04 08:55:42 +01:00
parent 12d8e33009
commit 3efca30a4c
4 changed files with 58 additions and 33 deletions

View file

@ -1,19 +1,47 @@
<?php
session_start();
createVotesDb();
function createVotesDb()
{
if (!file_exists("votes.json")) {
file_put_contents("votes.json", "{}");
}
global $votes;
$votes = json_decode(file_get_contents("votes.json"), true);
if (empty($votes)) {
$votes = [
"Pellegrini" => 0,
"Egonu" => 0,
"Vio" => 0,
"Totti" => 0,
"Tamberi" => 0,
"Rossi" => 0
];
file_put_contents("votes.json", json_encode($votes));
}
}
function checkPost()
{
unset($_SESSION["error"]);
if (empty($_POST["nome"]) || empty($_POST["eta"]) || empty($_POST["sesso"])) {
$_SESSION["error"] = "Dati mancanti";
header("Location: login.php");
exit();
}
if ($_POST["eta"] < 18) {
$_SESSION["error"] = "Devi avere 18 anni per entrare";
header("Location: login.php");
exit();
}
header("Location: login.php");
exit();
}
function checkSession()
@ -32,11 +60,4 @@ function checkHasVoted()
return false;
}
return true;
}
function addVote($film, $vote)
{
global $votes;
$votes[$film] += $vote;
file_put_contents("votes.json", json_encode($votes));
}