1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
| <?php
class Session Extends Sql
{ var $session ; // Ptr venant de l'instantioation de HTML
var $connect ;
function __construct($session)
{ $this->session = $session ;
user_error("Constructor SESSION" , E_USER_NOTICE) ;
if ($session)
{ user_error("Session starts CORRECTLY" , E_USER_NOTICE) ;
//
// Rsstore session data from table (if they exist, not true the first iteration)
// ============================================================================
// print_r($_SESSION) ;
//**** $_SESSION = unserialize($this->restore_session()) ;
}
else
user_error("Session didn't start FATAL ERROR" , E_USER_ERROR) ;
}
function __destruct()
{ user_error("Session destruct" , E_USER_NOTICE) ;
//
// Dump $_SESSION array to disk....
// ================================
//**** $this->dump_session(serialize($_SESSION)) ;
// print_r($_SESSION) ;
/*
$this->destroy() ;
$_SESSION = array();
session_destroy() ;
*/
}
/* ==================================================================================================================================== */
function add($key,$value)
{ user_error("Session[ADD] - key[".$key."] => value[".$value."]" , E_USER_NOTICE) ;
if ( isset($_SESSION[ $key ]) )
{ user_error("Impossible to Add Session Variable[ $key ] or already defined !" , E_USER_WARNING) ;
return(false) ;
}
else
{ $_SESSION[ $key ] = $value ;
return(true) ;
}
}
function set($key,$value)
{ if (isset($_SESSION[ $key ]))
{ $_SESSION[ $key ] = $value ;
return(true) ;
}
else
{ $_SESSION[ $key ] = $value ;
user_error("Variable SESSION{". $key ."] is supposed to exist !!!!" , E_USER_WARNING) ;
return(false) ;
}
}
function get($key)
{// SESSION[Get] ==> [IsConnected] is [] is that right ?
// user_error("SESSION_GET... just to check.... [". $key . "]" , E_USER_NOTICE) ;
if (isset($_SESSION[ $key ]))
user_error("SESSION[Get] ==> [" .$key . "] is [" . $_SESSION[ $key ] . "] is that right ?" , E_USER_WARNING) ;
else
user_error("SESSION[Get] ==> [". $key ."] is not defined !!!!!" , E_USER_WARNING) ;
// print_r($_SESSION) ;
return( (isset($_SESSION[ $key ])) ? $_SESSION[ $key ] : false) ;
}
function del($key)
{ if (isset($_SESSION[" $key "]))
unset($_SESSION[" $key "]) ;
}
function session_dump()
{// user_error("Session[ADD] - key[".$key."] - value[".$value."]" , E_USER_NOTICE) ; {
foreach($_SESSION as $key => $value) :
user_error("Session[DUMP] - key[" . $key . "] => Value[" . $value . "]", E_USER_NOTICE) ;
endforeach ;
//
// "endforeach" as seen in PHP.NET.....
// add this to the end of every foreach() you use
unset($key,$value) ;
}
function session_empty($logout=false)
{ user_error("Session [Empty]" , E_USER_NOTICE) ;
foreach($_SESSION as $key => $value)
if($key != "redirector" && ($key != "user" || $logout))
unset($_SESSION[ $key ]);
}
/* ==================================================================================================================================== */
/* ==================================================================================================================================== */
/* ==================================================================================================================================== */ function session_id()
{ return("jecrepahute_session_data") ; }
function restore_session()
{ user_error("Trying to Restore SESSION....." , E_USER_NOTICE) ;
$id = $this->session_id() ;
$sql = "select sessiondata
from sessions
where ID = '" . $id . "'" ;
$this->dbLink = Sql::open("session") ;
if ( !( $this->dbResult = Sql::query($sql, $this->dbLink)) )
return(false) ;
$dbRow = Sql::fetch_assoc($this->dbResult) ;
//
// Signale que la DB a été accédée
// ===============================
$upd = "UPDATE sessions " .
"SET " .
"lastaction = now() " .
"WEHRE ID = '" . $id . "'" ;
if ( !( $this->dbResult = Sql::query($sql, $this->dbLink)) )
return(false) ;
//
// retourne (enfin....) sessiondata !
// ==================================
return($dbRow["sessiondata"]) ;
}
function dump_session($session)
{ user_error("Trying To Store SESSION....." , E_USER_NOTICE) ;
$id = $this->session_id() ;
//
// Cfr Campus press PHP5 page 774
// ==============================
$this->dbLink = Sql::open("session") ;
//
// on crée la session si elle n'existe pas...
// ------------------------------------------
$isrt = "INSERT IGNORE into sessions ( ID ) VALUES ('" . $id . "' ) " ;
if ( !( $this->dbResult = Sql::query($isrt, $this->dbLink)) )
return(false) ;
//
// On actualise la seesion
// =======================
$updt = "UPDATE sessions " .
"SET " .
"sessiondata = '" . addslashes($session) . "' , " .
"lastaction = NOW() " .
"WHERE ID = '" . $id . "'" ;
if ( !( $this->dbResult = Sql::query($updt, $this->dbLink)) )
return(false) ;
return(true) ;
}
function destroy()
{ $dlet= "DELETE from sessions" .
"WHERE id = '" . $id . '"' ;
if ( !( $this->dbResult = Sql::query($sql, $this->dbConnect)) )
return(false) ;
return(true) ;
}
}
?> |