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`
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)
);
```

@ -64,6 +64,14 @@
* 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.
*/
@ -362,6 +370,13 @@
$dbc = pg_connect("host=$DB_HOST dbname=$DB_NAME user=$DB_USER password=$DB_PASSWORD")
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
$name = trim($_POST['name']);
@ -411,13 +426,13 @@
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<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>
<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>
<body class="center">
<center>
@ -552,7 +567,7 @@
the first 8 characters are used.
</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>
</div>

Loading…
Cancel
Save