
July 5th, 2000, 12:06 PM
|
|
Junior Member
|
|
Join Date: Jul 2000
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
The code seems correct but a little bit redundant
Try to consider this...
"<?
session_start(); ...
"
This call will load in memory the content of the current session, or will create a new one if no session is currently in use.
If your browser has already send a sessionId along with the request, then all variables stored in the session will be available.
Hence
"if (!$PHPSESSID) {
session_register('body_color');
session_register('text_color');
}
"
will not be executed even if a new session is established, due to first access to the resource ($PHPSESSID is always set).
Furthermore
"else if ((!$body_color) | | (!$text_color)) {
session_register('body_color');
session_register('text_color');
}
?>
"
is executed only on the first access to the resource, when no variable named 'body_color' or 'text_color' is in scope. The second time (do you mean that you use the same resource to test session? it seems ...) the resource is get from the same browser instance, the session_register() call will bring in scope
'body_color' and 'text_color', so the "if" part of "else" branch wil not be executed. Maybe this is the correct place where you will initialize those session variables.
Try this
"
<?
session_register('body_color');
session_register('text_color');
if ((!$body_color) | | (!$text_color)) {
$body_color=$somecolor1; // you will assign
// a color value here
$text_color=$somecolor2; // you will assign
// a color value here
}
// set body and text color to the values in
//$body_color and $text_color
....
?>
"
Note that session_register() calls
session_start().
I don't know your session expiration settings. Maybe something is wrong with the session expiration. The default value is 0 meaning that session wil expire when the browser instance will be closed.
Try to edit the session file in /tmp dir in order to verify correct value for session variables and verify that only one file is created. If more that one file is created then more than one session is spawned between two request.
Hope will help
PS: sorry if same error is included ... I have a little experience.
Ciao Ugo.
|