From c0097c387173a9af8ea562549d3cf8917b60ad51 Mon Sep 17 00:00:00 2001
From: Raghav <raghavsmart1213@gmail.com>
Date: Mon, 17 Mar 2025 05:56:35 +0000
Subject: [PATCH] Session class created

---
 _includes/Session.class.php | 51 +++++++++++++++++++++++++++++++++++++
 sg.php => sessiontest.php   |  9 +++++++
 2 files changed, 60 insertions(+)
 create mode 100644 _includes/Session.class.php
 rename sg.php => sessiontest.php (66%)

diff --git a/_includes/Session.class.php b/_includes/Session.class.php
new file mode 100644
index 0000000..28ba8ef
--- /dev/null
+++ b/_includes/Session.class.php
@@ -0,0 +1,51 @@
+<?php
+
+class Session
+{
+    // To start the session
+    public static function start()
+    {
+        session_start();
+    }
+
+    // To unset the session variables (delete the session variables)
+    public static function unset_all()
+    {
+        session_unset();
+    }
+
+    // To destroy the session(delete the session files)
+    public static function destroy()
+    {
+        session_destroy();
+    }
+
+    // To set the key and values in $session array
+    public static function set($key, $value)
+    {
+        $_SESSION[$key] = $value;
+    }
+
+    // To delete the required key values
+    public static function del($key)
+    {
+        unset($_SESSION[$key]);
+    }
+
+    // To check the given key is present
+    public static function isset($key)
+    {
+        return isset($_SESSION[$key]);
+    }
+
+    // To get the key value
+    public static function get($key, $default = false)
+    {
+        if(Session::isset($key)){
+            return $_SESSION[$key];
+        }else{
+            return $default;
+        }
+        
+    }
+}
diff --git a/sg.php b/sessiontest.php
similarity index 66%
rename from sg.php
rename to sessiontest.php
index 7ae74b6..8d4a07c 100644
--- a/sg.php
+++ b/sessiontest.php
@@ -6,12 +6,21 @@ session_start();
 
 print("_SESSION\n");
 print_r($_SESSION);
+print("Session ID = " . session_id()."\n");
 
 
 // To Clear the values in session array but not delete.
 if (isset($_GET['clear'])) {
     printf("Clearing....\n");
     session_unset();
+    print("Session ID[unset] = " . session_id()."\n");
+}
+
+// To destroy the session
+if (isset($_GET['destroy'])) {
+    printf("Destroying..\n");
+    session_destroy();
+    print("Session ID[destroyed] = " . session_id()."\n");
 }
 /*
 * We can assignment $_SESSION['A'];
-- 
GitLab