note 30346 deleted from function.session-start by bjori
| From: | bjori@php.net | Date: | Sun, 16 Apr 2006 00:16:49 +0000 |
| Subject: | note 30346 deleted from function.session-start by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-108203@lists.php.net to get a copy of this message | ||
Note Submitter: jeroen at unfix dot org
----
Ofcourse one can call the session functions from an object
and even stuff a class into the session, it just needs some tricks ;)
Example:
class Site()
{
var $db_open;
var $error;
function Site()
{
$this->db_open = false;
$this->error = "No errors";
}
function IsOpen()
{
return $this->db_open;
}
function OpenDB()
{
$this->error = "Not implemented";
}
}
function fireup()
{
global $site;
session_start();
if (isset($_SESSION["site"])) $site = &$_SESSION["site"];
else
{
$_SESSION["site"] = new Site();
$site = &$_SESSION["site"];
}
if (!$site->IsOpen() &&
!$site->OpenDB())
{
echo $site->error;
}
}
Now call the fireup() function from your main page et tada
$site is your globally retained class in which you can stuff interresting things like database
connections. Do remember to
declare them with 'var' in your class base like above.