<?php
$metodo = $_SERVER['REQUEST_METHOD'];
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<title>HTTP spiegato chiarissimo</title>
<style>
  body { font-family: Arial; }
  .big { font-size: 20px; margin: 10px 0; }
  .box { border: 2px solid black; padding: 15px; margin: 15px 0; }
  button { padding: 10px; margin: 5px; }
</style>
</head>
<body>

<h1>🌐 HTTP = CLIENT ↔ SERVER</h1>

<div class="box">
  <div class="big">📥 Il CLIENT ha mandato:</div>
  <div class="big"><strong>Metodo HTTP:</strong> <?= $metodo ?></div>
</div>

<div class="box">
  <div class="big">📤 Il SERVER risponde:</div>
  <div class="big">
    <?php
      if ($metodo === 'GET') echo "Sto LEGGENDO dei dati";
      if ($metodo === 'POST') echo "Sto RICEVENDO dei dati nuovi";
      if ($metodo === 'PUT') echo "Sto MODIFICANDO dei dati";
      if ($metodo === 'DELETE') echo "Sto CANCELLANDO dei dati";
    ?>
  </div>
</div>

<hr>

<h2>🔘 Premi un bottone (CLIENT)</h2>

<form method="GET">
  <button>GET → chiedi</button>
</form>

<form method="POST">
  <button>POST → invia</button>
</form>

<button onclick="manda('PUT')">PUT → modifica</button>
<button onclick="manda('DELETE')">DELETE → cancella</button>

<script>
function manda(metodo) {
  fetch('', { method: metodo })
    .then(() => location.reload());
}
</script>

</body>
</html>
