Liquid Fire Posted November 26, 2006 Share Posted November 26, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/28552-session-not-holding-info/ Share on other sites More sharing options...
.josh Posted November 26, 2006 Share Posted November 26, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/28552-session-not-holding-info/#findComment-130637 Share on other sites More sharing options...
Liquid Fire Posted November 26, 2006 Author Share Posted November 26, 2006 thinking about it more i am just going to scrap the entire class, it really does not provide me with anything useful like i though it might. Quote Link to comment https://forums.phpfreaks.com/topic/28552-session-not-holding-info/#findComment-130645 Share on other sites More sharing options...
Liquid Fire Posted November 26, 2006 Author Share Posted November 26, 2006 my bad, I am going to keep the class, i was calling $session->distroy at in the footer. I think i will just make is a singleton class. Quote Link to comment https://forums.phpfreaks.com/topic/28552-session-not-holding-info/#findComment-130648 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.