Jump to content

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. 
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.