diff --git a/_includes/Session.class.php b/_includes/Session.class.php new file mode 100644 index 0000000000000000000000000000000000000000..28ba8ef3dd80296d914dff31b2fb580fac163731 --- /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 7ae74b6d3bc12ff8a045ebe9c53c5b25a8818246..8d4a07cf108ca89a28365f418eeb58bf80c4946f 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'];