summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid T. Sadler <davidtsadler@googlemail.com>2021-10-18 21:15:18 +0100
committerDavid T. Sadler <davidtsadler@googlemail.com>2021-10-18 21:15:18 +0100
commit1a112ab14becaf6d41cd34c176cbe563d4ca9742 (patch)
treeaad7dd85d9a7d3d4465a6ef506a0259b46ed6ee7 /src
parentcbaedbc5251f3b127bd81242d1344c0cd3e56e0c (diff)
Implement session management
Diffstat (limited to 'src')
-rw-r--r--src/DTS/Session.php41
-rw-r--r--src/templates/index.php3
2 files changed, 44 insertions, 0 deletions
diff --git a/src/DTS/Session.php b/src/DTS/Session.php
new file mode 100644
index 0000000..956f4e5
--- /dev/null
+++ b/src/DTS/Session.php
@@ -0,0 +1,41 @@
+<?php
+
+declare(strict_types=1);
+
+namespace DTS;
+
+class Session
+{
+ private static ?self $instance = null;
+
+ private array $session;
+
+ public static function getInstance()
+ {
+ if (!self::$instance) {
+ self::$instance = new self();
+ }
+
+ return self::$instance;
+ }
+
+ private function __construct()
+ {
+ session_start();
+
+ foreach ($_SESSION as $key => $value) {
+ $this->session[$key] = $value;
+ unset($_SESSION[$key]);
+ }
+ }
+
+ public function set(string $key, string $value): void
+ {
+ $this->session[$key] = $_SESSION[$key] = $value;
+ }
+
+ public function get(string $key): ?string
+ {
+ return $this->session[$key] ?? null;
+ }
+}
diff --git a/src/templates/index.php b/src/templates/index.php
index ed84fd4..148a173 100644
--- a/src/templates/index.php
+++ b/src/templates/index.php
@@ -6,6 +6,9 @@
<title>Bookmarks</title>
</head>
<body>
+ <?php if ($message) { ?>
+ <p><?php echo $message; ?></p>
+ <?php } ?>
<a href="/create">Add</a>
<ul>
<?php foreach ($bookmarks as $bookmark) { ?>