From 0abfd4978197c6d05b065de84ae44118ae5e9149 Mon Sep 17 00:00:00 2001 From: marko Date: Mon, 20 Dec 2021 16:26:42 +0100 Subject: [PATCH] added loginLogging - jsonVersion --- homepage/participo/.htaccess | 7 +++++++ homepage/participo/login.php | 17 +++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 homepage/participo/.htaccess diff --git a/homepage/participo/.htaccess b/homepage/participo/.htaccess new file mode 100644 index 0000000..362484a --- /dev/null +++ b/homepage/participo/.htaccess @@ -0,0 +1,7 @@ +# Url-Rewriting aktivieren +RewriteEngine on +# Wenn * angefordert wurde und *.php existiert +RewriteCond %{REQUEST_FILENAME}.php -f +# Hänge ein \.php an +RewriteRule ^(.*)$ $1\.php + diff --git a/homepage/participo/login.php b/homepage/participo/login.php index aa386ef..218f967 100644 --- a/homepage/participo/login.php +++ b/homepage/participo/login.php @@ -36,14 +36,15 @@ function checkCredentials($username, $password, $db_server, $db_user, $db_passwo $message['success'] = 'Anmeldung erfolgreich, weiter zum Inhalt.'; PHPCount::AddHit("participo-Login-".$_POST['f']['username']); - $lastLogins=file("logins.txt"); - $file = fopen("logins.txt", "w"); - fwrite($file, $_POST['f']['username']."\n"); - for ( $i=0;i<30;++$i) - { - fwrite($file, $lastLoggins."\n"); - } - fclose($file); + // Logging Logins + $userName = $_SESSION['user']['username']; + $lastLogins = json_decode(file_get_contents("lastLogins.json"), true); + if(!array_key_exists($userName, $lastLogins)) + $lastLogins[$userName] = []; + if(!array_key_exists('lastLogins', $lastLogins[$userName])) + $lastLogins[$userName]['lastLogins'] = []; + $lastLogins[$userName]['lastLogins'] = array_merge( array( date('Y-m-d H:i:s') ), $lastLogins[$userName]['lastLogins'] ); + file_put_contents("lastLogins.json", json_encode($lastLogins)); header('Location: http://' . $_SERVER['HTTP_HOST'] . '/participo?user=' . $_POST['f']['username']); } else {