Skip to content
Snippets Groups Projects
Commit c0097c38 authored by Raghav's avatar Raghav
Browse files

Session class created

parent 22cb2d27
No related branches found
No related tags found
No related merge requests found
<?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;
}
}
}
......@@ -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'];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment