123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
-
- require_once "dbase.inc";
-
- //test input forms
- function test_input($data)
- {
- $data = trim($data);
- $data = stripslashes($data);
- $data = htmlspecialchars($data);
- return $data;
- }
-
- //send login info to db
- function loginUser()
- {
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
-
- global $dbase;
-
- $login = test_input($_POST["login"]);
- $password = test_input($_POST["password"]);
-
- if (!preg_match("/^[a-zA-Z0-9]+$/", $login)) {
- return "<span class=\"loginform__input__items errormessage\">ongeldige loginnaam, enkel letters en cijfers toegelaten</span>";
- }
-
- $loginQuery = $dbase->loginQuery($login, $password);
-
- // apart resultaat als spelerId niet in db
- if ($loginQuery) {
- $_SESSION['spelerId'] = $loginQuery['id'];
- $_SESSION['spelerNaam'] = $loginQuery['login'];
- header('Location: game.php');
- exit();
- } else {
- return "<span class=\"loginform__input__items errormessage\">Foutieve login of paswoord</span>";
- }
- }
- }
-
- //send register info to db
- function registerUser()
- {
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- global $dbase;
-
- $login = test_input($_POST["login"]);
- $password = test_input($_POST["password"]);
-
- if (!preg_match("/^[a-zA-Z0-9]+$/", $login)) {
- return "<span class=\"loginform__input__items errormessage\">ongeldige loginnaam, enkel letters en cijfers toegelaten</span>";
- }
-
- $queryResult = $dbase->registerQuery($login);
-
- if ($queryResult) {
- return "<span class=\"loginform__input__items errormessage\">Loginnaam al in gebruik</span>";
- } else {
- $dbase->registerInsert($login, $password);
- header('Location: index.php');
- exit();
- }
- }
- return;
- }
-
- //auto timeout after ... minutes
- function loginTimout()
- {
- if (!isset($_SESSION["logTime"])) {
- $_SESSION["logTime"] = time();
- }
-
- if (isset($_SESSION['spelerId'])) {
- $nu = time();
- $delta = $nu - $_SESSION["logTime"];
- if ($delta < 15 * 60) {
- $_SESSION["logTime"] = time();
- } else {
- session_unset();
- session_destroy();
- header("location: index.php");
- exit();
- }
- }
- }
-
-
- function checkLogin()
- {
- if (!($_SESSION['spelerId'] && isset($_SESSION['spelerNaam']))) {
- header('Location: index.php');
- exit();
- }
- }
-
-
- function logoutUser()
- {
- if (isset($_POST['logout'])) {
- session_destroy();
- header('Location: index.php');
- exit();
- }
- }
|