Logout_Action.php 900 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /**
  3. * File for the logout action.
  4. *
  5. * Implements an action function to be called from the {@see Controller}.
  6. *
  7. * @author Iñigo Valentin <i@inigovalentin.com>
  8. * @license https://www.gnu.org/licenses/gpl-3.0.en.html GNU General Public License V3
  9. * @package SWDB
  10. */
  11. require_once(PATH::ACTION . "Action.php");
  12. /**
  13. * Logs the user out and redirects to the login page.
  14. *
  15. * Invalidates cookies and session variables.
  16. *
  17. * @category Action
  18. */
  19. class Logout_Action extends Action{
  20. /**
  21. * Executes the action.
  22. */
  23. function execute(){
  24. setcookie("user_id", null, time() - 3600);
  25. setcookie("user_token", null, time() - 3600);
  26. session_regenerate_id();
  27. $_SESSION['session'] = false;
  28. $_SESSION['user_id'] = "";
  29. $this->code = 204;
  30. $this->message = "No content.";
  31. header("Location: /");
  32. return;
  33. }
  34. }