Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ## Class cSession()
- ##
- ## Written by Henric Johansson, henric-johansson@hotmail.com 2011-10-19
- ## Handles your $_SESSION variables
- class cSession {
- private $sessionStarted = false;
- function __construct() {
- ## Our constructor, initialize session here
- if(!$this->sessionStarted) {
- ## Start the session and set the variable
- session_start();
- $this->sessionStarted = true;
- }
- }
- ## Function get($key)
- ##
- ## Returns the value of $key, if variable was not set, returns false
- function get($key) {
- ## If we the key is not set, return nothing
- if(!isset($_SESSION[$key])) {
- return false;
- } else {
- ## If it is set, return the value.
- return $_SESSION[$key];
- }
- }
- ## Function set($value, $key)
- ##
- ## Sets a key $key to the value, $value
- function set($value, $key) {
- $_SESSION[$key] = $value;
- }
- ## Function debugSession()
- ##
- ## Prints the session variable in a prepared html tag if no session was set, echo an error message
- function debugSession() {
- if($this->sessionStarted) {
- echo '<pre>';
- print_r($_SESSION);
- echo '</pre>';
- } else {
- echo '<pre>';
- echo '$_SESSION not initialized';
- echo '</pre>';
- }
- }
- ## Function kill()
- ##
- ## Returns true if session was killed, returns false if there was no session
- function kill() {
- if($this->sessionStarted) {
- ## If session was started, destroy and unset it.
- session_unset();
- session_destroy();
- return true;
- } else {
- ## If there was no session, return false
- return false;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement