note 30346 added to function.session-start
| From: | jeroen at unfix dot org | Date: | Fri, 14 Mar 2003 18:24:58 +0000 |
| Subject: | note 30346 added to function.session-start | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-45316@lists.php.net to get a copy of this message | ||
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.
--
http://www.php.net/manual/en/function.session-start.php
http://master.php.net/manage/user-notes.php?action=edit+30346
http://master.php.net/manage/user-notes.php?action=delete+30346
http://master.php.net/manage/user-notes.php?action=reject+30346