desconectar.php 669 B

123456789101112131415161718192021222324252627
  1. <?php
  2. require_once "{$_SERVER['DOCUMENT_ROOT']}/dependencies.php";
  3. use Respect\Validation\Validator as v;
  4. // only requre POST ['action' => 'desconectar' | 'sign-out']
  5. methods([
  6. 'POST' => v::keySet(
  7. v::key('action', v::stringType()->notEmpty()->in(['desconectar', 'sign-out']))
  8. ), 'GET' => v::alwaysValid()
  9. ]);
  10. if ($_SERVER['REQUEST_METHOD'] === 'GET') {
  11. session_destroy();
  12. } else
  13. switch ($_POST['action']) {
  14. case 'desconectar':
  15. unset($_SESSION['page']);
  16. unset($_SESSION['moodle_db']);
  17. break;
  18. case 'sign-out':
  19. session_destroy();
  20. break;
  21. }
  22. header('Location: /');