From 4a4896e2a773ae6f5edc23be432a7d973467dca1 Mon Sep 17 00:00:00 2001
From: Sibidharan <sibidharan@icloud.com>
Date: Wed, 23 Feb 2022 15:55:10 +0000
Subject: [PATCH] session

---
 libs/includes/Session.class.php | 42 +++++++++++++++++++++++++++++++++
 libs/load.php                   |  4 +++-
 sg.php                          | 31 ++++++++++++++++++++++++
 3 files changed, 76 insertions(+), 1 deletion(-)
 create mode 100644 libs/includes/Session.class.php
 create mode 100644 sg.php

diff --git a/libs/includes/Session.class.php b/libs/includes/Session.class.php
new file mode 100644
index 00000000..82048081
--- /dev/null
+++ b/libs/includes/Session.class.php
@@ -0,0 +1,42 @@
+<?php
+
+class Session
+{
+    public static function start()
+    {
+        session_start();
+    }
+
+    public static function unset()
+    {
+        session_unset();
+    }
+    public static function destroy()
+    {
+        session_destroy();
+    }
+
+    public static function set($key, $value)
+    {
+        $_SESSION[$key] = $value;
+    }
+
+    public static function delete($key)
+    {
+        unset($_SESSION[$key]);
+    }
+
+    public static function isset($key)
+    {
+        return isset($_SESSION[$key]);
+    }
+
+    public static function get($key, $default=false)
+    {
+        if (Session::isset($key)) {
+            return $_SESSION[$key];
+        } else {
+            return $default;
+        }
+    }
+}
diff --git a/libs/load.php b/libs/load.php
index b532cd57..7c322bf9 100644
--- a/libs/load.php
+++ b/libs/load.php
@@ -1,9 +1,11 @@
 <?php
-
+include_once 'includes/Session.class.php';
 include_once 'includes/Mic.class.php';
 include_once 'includes/User.class.php';
 include_once 'includes/Database.class.php';
 
+Session::start();
+
 function load_template($name)
 {
     include $_SERVER['DOCUMENT_ROOT']."/app/_templates/$name.php"; //not consistant.
diff --git a/sg.php b/sg.php
new file mode 100644
index 00000000..75adc884
--- /dev/null
+++ b/sg.php
@@ -0,0 +1,31 @@
+<pre>
+<?php
+// setcookie("testcookie", "testvalue", time() + (86400 * 30), "/");
+include 'libs/load.php';
+
+print("_SESSION \n");
+print_r($_SESSION);
+print("_SERVER \n");
+print_r($_SERVER);
+
+if (isset($_GET['clear'])) {
+    printf("Clearing...\n");
+    Session::unset();
+}
+
+if (Session::isset('a')) {
+    printf("A already exists... Value: ".Session::get('a')."\n");
+} else {
+    Session::set('a', time());
+    printf("Assigning new value... Value: $_SESSION[a]\n");
+}
+
+if (isset($_GET['destroy'])) {
+    printf("Destroying...\n");
+    Session::destroy();
+}
+
+
+
+
+?></pre>
\ No newline at end of file
-- 
GitLab