config.inc.php 808 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. $db = new SQLite3('db/netsim.sqlite3');
  3. session_set_cookie_params(3600 * 24 * 30);
  4. session_start();
  5. $userq = $db->prepare("SELECT * FROM user WHERE name = :name");
  6. if (isset($_POST['username']) && isset($_POST['password'])) {
  7. $userq->bindValue(':name', $_POST['username']);
  8. $res = $userq->execute();
  9. if ($res === false) {
  10. $login_error = "Username or password incorrect.";
  11. } else {
  12. $res = $res->fetchArray();
  13. if (password_verify($_POST['password'], $res['password'])) {
  14. $_SESSION['cs4g_user_id'] = $res['id'];
  15. header('Location: ./');
  16. } else {
  17. $login_error = "Username or password incorrect.";
  18. }
  19. }
  20. } else if (isset($_GET['logout'])) {
  21. unset($_SESSION['cs4g_user_id']);
  22. session_destroy();
  23. header('Location: ./');
  24. }
  25. define('LOGGEDIN', isset($_SESSION['cs4g_user_id']));
  26. ?>