· 8 years ago · Aug 02, 2018, 06:06 AM
1<?php
2session_start();
3// Config
4$sqlhost = "localhost";
5$sqldatabase = "database";
6$sqlusername = "username";
7$sqlpassword = "password";
8// Amount of times a user can refresh within time limit (seconds)
9$refreshlimit = "10";
10$refreshtimer = "30";
11// End config
12
13// Check if banned for refreshing too fast.
14// If session vars dont exist then create them, else add 1 to count.
15if (!isset($_SESSION['first_hit'])) {
16 $_SESSION['first_hit'] = time();
17 $_SESSION['count'] = 1;
18 $_SESSION['banned'] = false;
19} else {
20 $timer = $_SESSION['first_hit'] + $refreshtimer;
21 // If timer has passed then reset all
22 if (time() > $timer) {
23 $_SESSION['count'] = 0;
24 $_SESSION['first_hit'] = time();
25 $_SESSION['banned'] = false;
26 } else {
27 // If timer has not passed then add 1 to refresh count
28 $_SESSION['count']++;
29 }
30}
31
32// Ban user if they refresh over x times within the x second time limit
33if ($_SESSION['count'] > $refreshlimit) {
34 $_SESSION['banned'] = true;
35}
36
37// If person is banned, stop loading page
38if ($_SESSION['banned'] == true) {
39 echo "<div align='center'>";
40 echo "<h2><strong>You reloaded the page too often. Come back in ";
41 echo $refreshtimer;
42 echo " seconds</strong></h2>";
43 echo "</div>";
44 die();
45}
46
47// Here comes the actual page content!
48// Start connection to database
49$connection = mysql_connect($sqlhost, $sqlusername, $sqlpassword) or die("Could not connect to database!");
50mysql_select_db($sqldatabase, $connection) or die("Connected but database not found!");
51
52// Get data from sqldb
53$result = mysql_query("SELECT name, reason, admin, time, temptime FROM banlist", $connection);
54
55// Create html table and top column
56echo "<table width=100% cellpadding=2 cellspacing=0 border=1 align=center> ";
57echo "<tr>";
58echo "<TD><B>Username</B>";
59echo "<TD><B>Ban Reason</B>";
60echo "<TD><B>Banned By</B>";
61echo "<TD><B>Banned On</B>";
62echo "<TD><B>Temp Ban</B>";
63echo "</tr>";
64
65// If data exists, fill in table
66while ($row = mysql_fetch_array($result)) {
67 echo "<tr>";
68 echo "<td>" . $row['Username'] . "</td>";
69 echo "<td>" . $row['Ban Reason'] . "</td>";
70 echo "<td>" . $row['Banned By'] . "</td>";
71 echo "<td>" . $row['Banned On'] . "</td>";
72 echo "<td>" . $row['Temp Ban'] . "</td>";
73 echo "</tr>";
74}
75
76// Finish table and close sql connection
77echo "</table>";
78mysql_close($connection);
79?>