php-school/similverifica/includes/security.php
2024-10-31 10:47:12 +01:00

42 lines
No EOL
1,011 B
PHP

<?php
session_start();
$votes = json_decode(file_get_contents("votes.json"), true);
function checkPost()
{
if (empty($_POST["nome"]) || empty($_POST["code"]) || empty($_POST["film"]) || empty($_POST["voto"])) {
$_SESSION["error"] = true;
header("Location: login.php");
exit();
}
if (trim($_POST["code"]) !== "a123") {
$_SESSION["error"] = true;
header("Location: login.php");
exit();
}
}
function checkSession()
{
if (empty($_SESSION["nome"]) || empty($_SESSION["code"]) || empty($_SESSION["film"]) || empty($_SESSION["voto"])) {
$_SESSION["error"] = true;
header("Location: login.php");
exit();
}
}
function checkHasVoted()
{
if (isset($_COOKIE["hasVoted"]) && $_COOKIE["hasVoted"]) {
$_SESSION["error"] = true;
return false;
}
return true;
}
function addVote($film, $vote)
{
global $votes;
$votes[$film] += $vote;
file_put_contents("votes.json", json_encode($votes));
}