From 021a8ee12016d25b397d75afe5e152eda42f8329 Mon Sep 17 00:00:00 2001 From: Pk11 Date: Tue, 21 Feb 2023 02:36:46 +0000 Subject: [PATCH] Add access counting --- README.md | 13 +++++++++++-- index.php | 23 +++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3484f6d..5d90421 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ this is a silly little BBS page I've thrown together out of a desite to have som 2. copy `vars.php.example` to `vars.php` 3. edit `vars.php` as explained in the file - ensure that your `image` and `thumb` folders exist -4. create the following table in the configured database: +4. create the following tables in the configured database: ```sql CREATE TABLE posts ( post_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, @@ -22,6 +22,15 @@ this is a silly little BBS page I've thrown together out of a desite to have som trip VARCHAR(10), email VARCHAR(256), comment VARCHAR(2048), - img VARCHAR(256) + img VARCHAR(256), + thumb_width INT, + thumb_height INT + ); + ``` + ```sql + CREATE TABLE access ( + count INT, + lock BOOL PRIMARY KEY DEFAULT TRUE, + CONSTRAINT lock_unique CHECK(lock) ); ``` diff --git a/index.php b/index.php index 97d3fe0..517323e 100644 --- a/index.php +++ b/index.php @@ -63,6 +63,14 @@ * comment VARCHAR(2048), * img VARCHAR(256) * ); + * + * CREATE TABLE access + * count INT, + * lock BOOL PRIMARY KEY DEFAULT TRUE, + * CONSTRAINT lock_unique CHECK(lock) + * ); + * + * INSERT INTO access VALUES (0); * * Finally, you will also need ffmpeg and exiftool installed for * metadata stripping and thumbnail conversion. @@ -360,7 +368,14 @@ // Connect to the database $dbc = pg_connect("host=$DB_HOST dbname=$DB_NAME user=$DB_USER password=$DB_PASSWORD") - or die('Could not connect: ' . pg_last_error()); + or die('Could not connect: ' . pg_last_error()); + + $access_count = 0; + { + pg_query('UPDATE access SET count=count+1;') or die('Query failed ' . pg_last_error()); + $res = pg_query('SELECT count FROM access') or die('Query failed: ' . pg_last_error()); + $access_count = pg_fetch_array($res)['count']; + } if($_POST['submit'] == 'Post') { // Grab the data from the POST @@ -411,13 +426,13 @@ - + BBS | ピケ.コム - +
@@ -552,7 +567,7 @@ the first 8 characters are used.

- The year is , but no ©. This page was generated in seconds. + The year is , but no ©. This page was generated in seconds and has been accessed times.