<?

    // ensure complete form was submitted
    if (!isset($_POST["name"]) || !isset($_POST["item"]))
    {
        header("Location: http://www.cs75.net/lectures/5/src/lunch/lunch.php");
        exit;
    }

    // open CSV file for appending
    $handle = fopen("orders.csv", "a");

    // acquire exclusive lock
    flock($handle, LOCK_EX);

    // add order to CSV file
    $order = array($_POST["name"], $_POST["item"]);
    fputcsv($handle, $order);
    fclose($handle);

?>

<!DOCTYPE html PUBLIC
     "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Lunch</title>
  </head>
  <body>
    One <?= $_POST["item"] ?> for <?= $_POST["name"] ?>, coming right up!
  </body>
</html>
