Jump to content

Session not holding info


Liquid Fire

Recommended Posts

I have created a session class here
[code]class CSession
{
function __construct()
{
$this->Initialize();
}
/*
function __destructor()
{
}

function __clone()
{
}
*/
public function Initialize()
{

session_start();
}

public function Destory()
{
session_unset();
session_destroy();
}

public function SetValue($variable_name, $variable_value)
{
$_SESSION[$variable_name] = $variable_value;
}

public function GetValue($variable_name)
{
return $_SESSION[$variable_name];
}

public function CheckValue($variable_name, $check_value)
{
if($_SESSION[$variable_name] == $check_value)
{
return true;
}
else
{
return false;
}
}

public function IsValueSet($variable_name)
{
if(isset($_SESSION[$variable_name]))
{
return true;
}
else
{
return false;
}
}
}
?>[/code]

now what i do in the header.php, which is require_once() in every file the a user can see, is call:

[code]$session = new CSession();[/code]

for some reason none of the value in $_SESSION and being stored, anyone can help me on why?
Link to comment
https://forums.phpfreaks.com/topic/28552-session-not-holding-info/
Share on other sites

okay so you made a new object called $session and you have a __contstruct which calls Initialize when you instantiated $session. All Initialize() does is session_start();.  It doesn't actually call your other methods, like SetValue or anything. After

$session = new CSession();

you need to add something like

$session->SetValue("somevariablename","somevalue");

however, i'm not sure you are really going about this the right way.  It doesn't make sense for you to make a new object like that for every single page.  It kind of defeats the purpose of session vars?

I think what you should probably be doing is remove the Initialize method from your class and just put session_start(); at the top of your pages.  Then declare your class in a require_once() somewhere, make your object and then carry your object over as a session variable. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.