Add access counting

main
Pk11 2 years ago
parent e564a89083
commit 021a8ee120

@ -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` 2. copy `vars.php.example` to `vars.php`
3. edit `vars.php` as explained in the file 3. edit `vars.php` as explained in the file
- ensure that your `image` and `thumb` folders exist - 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 ```sql
CREATE TABLE posts ( CREATE TABLE posts (
post_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, 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), trip VARCHAR(10),
email VARCHAR(256), email VARCHAR(256),
comment VARCHAR(2048), 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)
); );
``` ```

@ -63,6 +63,14 @@
* comment VARCHAR(2048), * comment VARCHAR(2048),
* img VARCHAR(256) * 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 * Finally, you will also need ffmpeg and exiftool installed for
* metadata stripping and thumbnail conversion. * metadata stripping and thumbnail conversion.
@ -360,7 +368,14 @@
// Connect to the database // Connect to the database
$dbc = pg_connect("host=$DB_HOST dbname=$DB_NAME user=$DB_USER password=$DB_PASSWORD") $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') { if($_POST['submit'] == 'Post') {
// Grab the data from the POST // Grab the data from the POST
@ -411,13 +426,13 @@
<head> <head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#DBA9B9"> <meta name="theme-color" content="#DBA9B9" />
<title>BBS | ピケ.コム</title> <title>BBS | ピケ.コム</title>
<link rel="alternate" type="application/rss+xml" title="RSS feed" href="/rss.php" /> <link rel="alternate" type="application/rss+xml" title="RSS feed" href="/rss.php" />
<link href="<?php echo ASSETS_PATH . 'style.css'; ?>" rel="stylesheet"> <link href="<?php echo ASSETS_PATH . 'style.css'; ?>" rel="stylesheet" />
</head> </head>
<body class="center"> <body class="center">
<center> <center>
@ -552,7 +567,7 @@
the first 8 characters are used. the first 8 characters are used.
</p> </p>
<p> <p>
The year is <?php echo date('Y'); ?>, but no &copy;. This page was generated in <?php printf("%.2f", microtime(true) - $start_time); ?> seconds. The year is <?php echo date('Y'); ?>, but no &copy;. This page was generated in <?php printf("%.2f", microtime(true) - $start_time); ?> seconds and has been accessed <?php echo $access_count; ?> times.
</p> </p>
</div> </div>

Loading…
Cancel
Save