Brain Taxing Session Problem
Posted: Thu Dec 16, 2004 4:59 pm
Hi,
I'm posting here as a last resort. This problems quite a long one and to answer it your going to have to either spot something obvious I have over looked or have written PHP lol. I have discussed this problem with a fellow coder to no avail. This is really getting at me. It's never good enough for me to fix something I have to know why it was broken.
The problem I have is not so much of a problem as it is a question. I have fixed my problem but it's not good enough, I want to know it's cause.
I'll explain more. I have build (and still am building) my own CMS (http://lostheaven.co.uk) for an example of it. Sessions have never been a problem until I created some code to read some session variables.
I normally read variables like this:
This works perfectly fine for most people. The code above uses the function below:
Pretty simple stuff. Here's the problem. When I use that method for getting the session details sometimes it dosn't always work on users PC. It either does work for you or it dosn't. It dosn't work one time and not the other. For some people it works for others it dosn't.
If I get the session variables this way:
It works all the time for everyone. So that's the problem fixed but why does it do this?
I'm posting here as a last resort. This problems quite a long one and to answer it your going to have to either spot something obvious I have over looked or have written PHP lol. I have discussed this problem with a fellow coder to no avail. This is really getting at me. It's never good enough for me to fix something I have to know why it was broken.
The problem I have is not so much of a problem as it is a question. I have fixed my problem but it's not good enough, I want to know it's cause.
I'll explain more. I have build (and still am building) my own CMS (http://lostheaven.co.uk) for an example of it. Sessions have never been a problem until I created some code to read some session variables.
I normally read variables like this:
Code: Select all
variable($session_username, 'users_username', 'session', NULL);
variable($session_user_id, 'users_user_id', 'session', NULL);Code: Select all
function variable(&$variable, $name, $type, $define_as) {
if (phpversion() <= "4.1.0") {
$GET = &$GET_VARS;
$POST = &$POST_VARS;
$SESSION = &$HTTP_SESSION_VARS;
$COOKIE = &$COOKIE_VARS;
$SERVER = &$HTTP_SERVER_VARS;
$ENV = &$HTTP_ENV_VARS;
} else {
$GET = &$_GET;
$POST = &$_POST;
$SESSION = &$_SESSION;
$COOKIE = &$_COOKIE;
$SERVER = &$_SERVER;
$ENV = &$_ENV;
}
if (eregi('get', $type)) {
$type = $GET;
} elseif (eregi('post', $type)) {
$type = $POST;
} elseif (eregi('session', $type)) {
$type = $SESSION;
} elseif (eregi('cookie', $type)) {
$type = $COOKIE;
} elseif (eregi('server', $type)) {
$type = $SERVER;
} elseif (eregi('env', $type)) {
$type = $ENV;
}
if (isset($type[$name])) {
// Escape those damn quotation marks!
if (!get_magic_quotes_gpc()) {
$variable = addslashes($type[$name]);
} else {
$variable = $type[$name];
}
}
else { $variable = $define_as; }
}If I get the session variables this way:
Code: Select all
$session_username = $_SESSION['users_username'];
$session_user_id = $_SESSION['users_user_id'];