diff --git a/base/autoloader.php b/base/autoloader.php
new file mode 100644
index 0000000..e39cf24
--- /dev/null
+++ b/base/autoloader.php
@@ -0,0 +1,7 @@
+
-
+
Colour Selector
@@ -10,8 +10,8 @@
-
+
Theme Switcher
@@ -10,8 +10,8 @@
-
+
Counter DB Tester
@@ -10,13 +10,13 @@
This is a dummy test for the database Counter
-
+
\ No newline at end of file
diff --git a/tasks/calc/index.php b/tasks/calc/index.php
index 857c615..e43446a 100644
--- a/tasks/calc/index.php
+++ b/tasks/calc/index.php
@@ -2,7 +2,7 @@
-
+
Calculator
@@ -11,8 +11,8 @@
-
+
Counter
@@ -10,8 +10,8 @@
-
+
Functions
-
+
Functions 2
-
+
Guest Book
@@ -13,10 +13,10 @@
-
+
Guest Book DB
@@ -15,14 +15,14 @@
-
+
\ No newline at end of file
diff --git a/tasks/guestBookDB/login.php b/tasks/guestBookDB/login.php
index a4bd28f..50d7adc 100644
--- a/tasks/guestBookDB/login.php
+++ b/tasks/guestBookDB/login.php
@@ -2,7 +2,7 @@
-
+
Guest Book DB - Login
@@ -12,9 +12,9 @@
-
+
Guest Book DB - Register
@@ -11,9 +11,9 @@
-
+
@@ -11,12 +11,12 @@
db = DB::openConnection();
+
+ if (empty($siteID)) {
+ $this->siteID = substr($_SERVER["REQUEST_URI"], strlen($_SERVER["REQUEST_URI"]) - 256);
+ } else {
+ $this->siteID = $siteID;
+ }
+ }
+
+ /*
+ * Render Component
+ */
+
+ public function render()
+ {
+ $this->cleanupIPs();
+ $hasVisited = $this->hasVisited();
+ if (!$hasVisited) {
+ $this->addHit();
+ $this->addIp();
+ }
+
+ $ret =
+ <<
+ .span-v3Yq3 {
+ display: inline-block;
+ padding: 6px 6px 4px;
+ border-radius: 3px;
+ background: #cccccc;
+ margin-right: -2px;
+ }
+
+ .center-v3Yq3 {
+ display: flex;
+ justify-content: center;
+ gap: 5px;
+ width: 50%;
+ margin: 20px auto;
+ }
+
+ .message-v3Yq3 {
+ color: #aaaaaa;
+ font-size: 12px;
+ text-align: center;
+ }
+
+
+
+ EOT;
+ foreach (mb_str_split(($this->getHits()) . "") as $digit) {
+ $ret .=
+ <<
$digit
+ EOT;
+ }
+ $ret .=
+ <<
+
+ Have visited this site.
+ EOT;
+ if (!$hasVisited) {
+ $ret .=
+ <<
+ This is your first visit tody
+ EOT;
+ }
+ $ret .=
+ <<
+
+ EOT;
+
+ echo $ret;
+ }
+
+ /*
+ * Implementation
+ */
+
+ private function getHits()
+ {
+ $query = "
+ SELECT
+ hits
+ FROM
+ Counter
+ WHERE
+ siteID LIKE :SID";
+
+ $stmt = $this->db->prepare($query);
+ $stmt->bindValue(":SID", $this->siteID);
+ $stmt->execute();
+ $hits = $stmt->fetch(PDO::FETCH_COLUMN);
+ return $hits !== false ? $hits : 0;
+ }
+
+ private function addHit()
+ {
+ $query = "
+ INSERT INTO
+ Counter(siteID, hits)
+ VALUES
+ (:SID, 1)
+ ON DUPLICATE KEY UPDATE
+ hits = hits + 1";
+
+ $stmt = $this->db->prepare($query);
+ $stmt->bindValue(":SID", $this->siteID);
+ $stmt->execute();
+ }
+
+ private function addIP()
+ {
+ $query = "
+ INSERT INTO
+ CounterIP(siteID, ip, timestamp)
+ VALUES
+ (:SID, :IP, NOW())";
+
+ $stmt = $this->db->prepare($query);
+ $stmt->bindValue(":SID", $this->siteID);
+ $stmt->bindValue(":IP", $_SERVER['REMOTE_ADDR']);
+ $stmt->execute();
+ }
+
+ private function cleanupIPs()
+ {
+ $query = "
+ DELETE FROM
+ CounterIP
+ WHERE
+ TIMESTAMPDIFF(MINUTE, timestamp, NOW()) > 1";
+
+ $stmt = $this->db->prepare($query);
+ $stmt->execute();
+ }
+
+ private function hasVisited()
+ {
+ $query = "
+ SELECT
+ COUNT(*)
+ FROM
+ CounterIP
+ WHERE
+ siteID = :SID
+ AND
+ ip = :IP
+ AND
+ TIMESTAMPDIFF(MINUTE, timestamp, NOW()) <= 1";
+
+ $stmt = $this->db->prepare($query);
+ $stmt->bindValue(":SID", $this->siteID);
+ $stmt->bindValue(":IP", $_SERVER['REMOTE_ADDR']);
+ $stmt->execute();
+ $cnt = $stmt->fetch(PDO::FETCH_COLUMN);
+ return $cnt > 0;
+ }
+}
diff --git a/tasks/oop/counter/index.php b/tasks/oop/counter/index.php
new file mode 100644
index 0000000..f881c39
--- /dev/null
+++ b/tasks/oop/counter/index.php
@@ -0,0 +1,21 @@
+
+
+
+
+
+
+ FieldValidator Test
+
+
+
+ render();
+ ?>
+
+
+
\ No newline at end of file
diff --git a/tasks/oop/fieldValidator/index.php b/tasks/oop/fieldValidator/index.php
index 6c838f8..4ba0720 100644
--- a/tasks/oop/fieldValidator/index.php
+++ b/tasks/oop/fieldValidator/index.php
@@ -2,19 +2,19 @@
-
+
FieldValidator Test
-
+
FormValidator Test
-
+
Person Test
-
+
Person Test