PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
First thing I would ask you is: Why are you assigning a super global to a member variable? Why not just use the SESSION global everywhere...
I think the problem however is in your assignment of the SESSION global to your member variable.
Whats actually happening is your creating a copy of the session variable and storing it in the member variable, so you could possibly try usig a reference:
the reason i want to do that is because i don't want to use the superglobal everywhere. i'm guessing that i'll have to but i just don't think it's a good way of doing things is all.
i wanted to grab just that part of the sessions global. so i could make a user/config and whatnot for sessions.
i'm guessing that i'll just have to do that. the sessions are really only accessable thru the user class anyways. it's just really bothering me that i can't do that. i swear i did it somewhere else and just doesn't work at all
I was going to say it worked for me, but I forgot I had used namespaces in my session class... for reference, here it is... and I agree with not using globals within a class... it just seems (to me) to defeat the purpose of OOP (although, I guess it really makes no difference, just gives the illusion of encapsulation, which is good enough for me )
/**
* Session handler
*
* A class for working with a session. This class is extended
* to provide a particular object or area of an application with its
* own namespace within the session data. This allows for different
* classes to play nicely together and not overwrite or delete session
* data they aren't supposed to.
*
* @author Luke Visinoni <luke.visinoni@gmail.com>
* @copyright Luke Visinoni August 20th 2006
*/
class Session extends Registry{
/**
* Container for session id
* @access protected
* @var string
* @static
*/
var $id = null;
/**
* This particular instance's namespace
* @access public
* @var string
*/
var $namespace;
/**
* Set to true if you would like for session's id to be regenerated
* @access protected
* @var bool
*/
var $regenerate;
/**
* Constructor
* @param string $namespace
* @param bool $regenerate
*/
function Session($namespace='Session', $regenerate=null) {
$this->namespace = $namespace;
$this->regenerate = $regenerate;
$this->start();
}
/**
* Initialize the session
*
* This method starts the session. Once the session is started, it tries to correct
* a known IE problem. (Need to find out more about this problem). Now it checks
* regenerates the session id, if specefied, and associates entries with our session.
*
* @access public
* @todo research ie problem that the session_cache_limiter is supposed to fix
*/
function start(){
if(session_id() == ''){
session_start();
if (strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE')){
session_cache_limiter('must-revalidate');
}
$this->id = session_id();
}
if ($this->regenerate){
session_regenerate_id();
}
$this->entries =& $_SESSION[$this->namespace];
}
}
?>
well PHP doesn't actually support namespaces at the moment, but arborint showed me a cool way to implement them by way of array indeces when working with session data. See how I am (for each instance of this class) setting a new index in the session superglobal with that particular object's namespace as the key?
see, i tried that and i got the information in there but i couldn't access it directly. i did print_r on it and it showed all the information but if i echo it out directly i get squat
ok, i got it to work. thanx NSG. the name spaces did work i was over looking stuff like normal and it all makes sense now. it's perfect
i was just hoping that i could setup a full multidimensional array into a user variable. either way i've gotten it to work and i'm extremely happy about it
thanx alot
now i can finish this thing by the end of this weekend and work on my custome groups/ACL's code