I’m using the $_SESSION superglobal in my multi-user tasks development instead of the older $HTTP_SESSION_VARS superglobal. To keep backward compatability, I was creating a $_SESSION variable if one didn’t already exist and just setting it to $HTTP_SESSION_VARS. This way, I could just always look for the $_SESSION variable and still be compatible with older versions of PHP.
Then I ran into some trouble.
If you are running a version of PHP that doesn’t have the $_SESSION variable, I need to declare the $_SESSION variable I created as a global variable within a function if I want to reference the data in the $_SESSION. If I declare the $_SESSION variable as global in a version of PHP that already has the $_SESSION variable, I break it.
One solution would be to write my own code for putting and retrieving data into sessions. I could wrap everything and talk to either the $_SESSION or $HTTP_SESSION_VARS as needed. I’d also have to do this for the $_REQUEST variable and others. This would be a lot of extra code. Actually, I bet I’ve already broken this somewhere. Turning on globals is not an option.
I think I’m just going to require PHP 4.2 or later and call it good. Solutions, comments and constructive arguments for backward compatability are welcome.
UPDATE: Hmm, actually I could pretty easily include a ‘compatible_vars.inc.php’ page that did the checking and global-ing
This post is part of the project: Tasks Pro™. View the project timeline for more context on this post.
In one of my projects, what I did was create a light messenger object that is passed to functions/methods/objects. In the constructor for this object, all variables in $_GET, $_POST, and $_SESSION are turned into object variables. Not the most elegant solution, with problems of its own, but it alowed me to overcome a similar problem.
[…] uperglobals Hack I’ve added my superglobals hack to tasks. The code looks like this: This file (superglobals.inc.p […]
I need your help in fixen the code i am using for my internet sever.My login page is written using a lot of session butits not bringng the sessions from one page to the next and I cant figure out why could you help me with this promblem if so could you email me back
using the $_SESSION but i can’t understand why this used?