title: unsetting session variable before setting it again results in 'undefined index' on use
body: <p>I'm unsetting some session variables before setting them again, but I've found that they result in <code>undefined index</code> on usage.</p>
  
  <p>I removed the line that unsets the variables before setting them again and that works well.</p>
  
  <p>I don't understand why unsetting them before resetting them yields <code>undefined index</code> on the next page.</p>
  
  <p><strong>recovery.php</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  @session_start();
  unset($_SESSION['reco-id'], $_SESSION['reco-code']);
  
  require_once $_SERVER["DOCUMENT_ROOT"] . "/php/autoloader.php";
  
  if (!isset($_POST['form-recovery-submit'])) return FormUtils::redirect_with_message("Acceso inválido", "/index", true);
  
  $id = $_POST["form-recovery-id"];
  
  $sql = new MySQL();
  
  if (FormUtils::checkIsEmail($id)) {
      $success = FormUtils::formValidateEmail($id);
  
      if (!$success['success']) return FormUtils::redirect_with_message($success["message"], "/register?reg=0", true);
  
      $id = $success['message'];
      $user = $sql-&gt;getUserByEmail($id);
  
      if (!$user) FormUtils::redirect_with_message("Ingresaste un email incorrecto o inexistente.", "/register?reg=2", true);
  } else {
      $success = FormUtils::formValidateNickname($id);
  
      if (!$success['success']) return FormUtils::redirect_with_message($success["message"], "/register?reg=0", true);
  
      $id = $success['message'];
      $user = $sql-&gt;getUserByNickname($id);
  
      if (!$user) FormUtils::redirect_with_message("Ingresaste un usuario incorrecto o inexistente.", "/register?reg=2", true);
  }
  
  
  $code = "327" . random_int(1000, 9999);
  $_SESSION["reco-id"] = $id;
  $_SESSION["reco-code"] = intval($code);
  
  FormUtils::sendNoReplyEmail("Recuperación de credenciales", "Ingresá el siguiente código para recuperar tus credenciales: $code", $user-&gt;getEmail());
  ?&gt;
  
  &lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  
  &lt;head&gt;
      &lt;?php include $_SERVER["DOCUMENT_ROOT"] . '/templates/meta.php' ?&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;?php include $_SERVER["DOCUMENT_ROOT"] . '/templates/header.php' ?&gt;
      &lt;div class="app"&gt;
          &lt;div class="app-wrapper"&gt;
              &lt;div&gt;
                  &lt;p&gt;Por favor, ingresá el código de confirmación que enviamos a tu email.&lt;/p&gt;
                  &lt;form action="/php/recovery_confirm.php" method="POST"&gt;
                      &lt;label for="recovery-code"&gt;Código de confirmación:&lt;/label&gt;
                      &lt;input type="text" name="recovery-code" id="recovery-code"&gt;
                      &lt;label for="recovery-newpass"&gt;Ingresá tu nuevo password:&lt;/label&gt;
                      &lt;input type="text" name="recovery-newpass" id="recovery-code"&gt;
                      &lt;button type="submit" name="recovery-code-submit"&gt;Enviar&lt;/button&gt;
                  &lt;/form&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="footer"&gt;
              &lt;?php include $_SERVER["DOCUMENT_ROOT"] . "/templates/footer.php" ?&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>recovery_confirm.php</strong>:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  @session_start();
  require_once $_SERVER["DOCUMENT_ROOT"] . "/php/autoloader.php";
  
  if (!isset($_POST["recovery-code-submit"])) return FormUtils::redirect_with_message("Acceso inválido.", "/index", true);
  if (!isset($_POST["recovery-code"])) return FormUtils::redirect_with_message("El código no puede estar en blanco", "/register?reg=2", true);
  
  //check password
  $success = FormUtils::formValidatePass($_POST["recovery-newpass"]);
  
  if (!$success['success']) return FormUtils::redirect_with_message($success["message"], "/register?reg=2", true);
  else {
      $pass = $success['message'];
  }
  
  $id = $_SESSION["reco-id"];
  $code = $_SESSION["reco-code"]; // undefined index
  $verify_code = intval($_POST["recovery-code"]); // undefined index
  
  if ($code !== $verify_code) return FormUtils::redirect_with_message("El código introducido no es válido!", "/register?reg=2", true);
  
  $sql = new MySQL();
  $conn = $sql-&gt;getConnection();
  
  if (FormUtils::checkIsEmail($id)) {
      $query = mysqli_query($sql-&gt;getConnection(), "UPDATE `users` SET `pass` = '$pass' WHERE `users`.`Mail` = '$id';");
  } else {
      $query = mysqli_query($sql-&gt;getConnection(), "UPDATE `users` SET `pass` = '$pass' WHERE `users`.`nick` = '$id';");
  }
  
  
  if (!$query) FormUtils::redirect_with_message("Hubo un error al actualizar tu password. Intentalo nuevamente.", "/register?reg=2", true);
  
  $sql-&gt;getConnection()-&gt;close();
  return FormUtils::redirect_with_message("Tu password ha sido actualizada correctamente!", "/register?reg=1", false);
  
  </code></pre>