Skip to content
View in the app

A better way to browse. Learn more.

Learn more

long-jump-web-stats/web/ranking.php.txt

ranking.php.txt
82 lines · 2.7 KB · Text
Raw
<?php
/*
 * Long Jump ranking (olds.ro workshop card LIB-0973) - read-only web page for the table that
 * the AMX Mod X plugin olds_ljweb fills. Upload this file as ranking.php, and ranking.css, to
 * the web host.
 * Copyright (C) 2026 daemon (olds.ro). GPL-3.0-or-later.
 *
 * Use a MySQL user that may only SELECT from the table, for example:
 *   GRANT SELECT ON gamedb.olds_lj TO 'ljweb'@'localhost' IDENTIFIED BY '...';
 */

// ---- settings: fill these in on the web host -------------------------------------------
$DB_HOST  = 'localhost';
$DB_NAME  = 'gamedb';
$DB_USER  = 'ljweb';
$DB_PASS  = '';
$DB_TABLE = 'olds_lj';      // the same as olds_ljw_table
$LIMIT    = 100;            // rows shown
// ---------------------------------------------------------------------------------------

header('Content-Type: text/html; charset=utf-8');

function h($text)
{
    return htmlspecialchars((string)$text, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}

$rows = [];
$problem = '';
if (!preg_match('/^[A-Za-z0-9_]{1,64}$/', $DB_TABLE)) {
    $problem = 'The table name in ranking.php is not valid.';
} else {
    try {
        $pdo = new PDO('mysql:host=' . $DB_HOST . ';dbname=' . $DB_NAME . ';charset=utf8mb4', $DB_USER, $DB_PASS, [
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
            PDO::ATTR_EMULATE_PREPARES => false,
        ]);
        $query = $pdo->prepare('SELECT name, steamid, distance, pre, date FROM `' . $DB_TABLE . '` ORDER BY distance DESC, date ASC LIMIT ?');
        $query->bindValue(1, (int)$LIMIT, PDO::PARAM_INT);
        $query->execute();
        $rows = $query->fetchAll();
    } catch (PDOException $e) {
        error_log('ranking.php: ' . $e->getMessage());
        $problem = 'The ranking is not available right now.';
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Long jump ranking</title>
<link rel="stylesheet" href="ranking.css">
</head>
<body>
<main>
<h1>Long jump ranking</h1>
<?php if ($problem !== ''): ?>
<p class="note"><?= h($problem) ?></p>
<?php elseif (!$rows): ?>
<p class="note">No records yet.</p>
<?php else: ?>
<table>
<thead><tr><th>#</th><th>Player</th><th>Distance</th><th>Pre-speed</th><th>Date</th></tr></thead>
<tbody>
<?php foreach ($rows as $i => $row): ?>
<tr>
<td class="num"><?= $i + 1 ?></td>
<td title="<?= h($row['steamid']) ?>"><?= h($row['name']) ?></td>
<td class="num"><?= h(number_format((float)$row['distance'], 2)) ?></td>
<td class="num"><?= h(number_format((float)$row['pre'], 0)) ?></td>
<td><?= h($row['date']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</main>
</body>
</html>

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.