Voting system with php and cookies

0

I'm trying to do an exercise for class, the statements are as follows:

The voting system only allows you to vote once, the next time you try to vote you must show a message that says, you have already voted (and the team you have voted for). From this exercise I only need to know how I can make the name of the team voted previously in the second message

In the second exercise, the same, but this time we will be able to vote twice, evidently the names will have to be shown.

The third can vote three times, but leaving a margin of 10 seconds.

The truth is I'm pretty lost in these last two years, to see if anyone can help me, this is the code I have done so far:

File dades.php:

<?php
  //variable global amb tots els equips que
  //es poden votar.
  $equips = array(
      0 => 'Barça',
      1 => 'Real Madrid',
      2 => 'Girona',
      3 => 'Espanyol'
  );
?>

Main file index.php:

<html>
    <?php
    if($_SERVER['REQUEST_METHOD'] == 'POST') {
        $cookie_name = "votar";
        $cookie_value = "1";
        setcookie($cookie_name, $cookie_value, time() + (30 * 24 * 3600));
    }
    ?>
    <header></header>
    <head>
    </head>
    <body>
    <H1>FIFA WORLD PLAYERS 2018</H1>  
    <form method="post">
        <?php
            include_once "dades.php";

        if($_SERVER['REQUEST_METHOD'] != 'POST'){
            foreach ($equips as $equip) {
                echo "<input type='radio' name='equip' value='$equip'/>$equip<br/>";
            }
            echo "<br/>";
            echo "<input type='submit' value='Enviar'>";
            echo '</form>';
        }else {
            $equip = $_POST["equip"];

            if (!isset($_COOKIE[$cookie_name])) {
                echo 'Has votat a ' . $_POST["equip"];
            } else {
                echo '<br>No pots votar més';
            }
        }
        ?>
    </body>
</html>
    
asked by THR4SH3RP0L0 14.02.2018 в 20:19
source

0 answers