Hi,

Problem: I register a session variable and assign a value to it. The
value is lost when I try to access it from a different webpage later.
Must I use custom session_save_handler functions if I want to extend the
life of a variable's value from Webpage to Webpage?

Details:
I'm using PHP's session management (PHP 4.0.3pl1). session.save_handler
is set by default to files. According to the manual track_vars is always
enabled for this version of PHP.
I use the following code to manage my session. It is contained in a
include file that is shared by all PHP pages:

  session_save_path("/usr/some/path/html/sessions/");
  session_start();  
  $registered_user_key = false;
  if ( ! session_is_registered("user_key") ) {
    session_register("user_key");
    $HTTP_SESSION_VARS["user_key"] = "dummy";
    $registered_user_key = true;
  }  
  
  function log_user_key($user_key = false) {
    global $HTTP_SESSION_VARS, $set_user_key, $get_user_key;

    $HTTP_SESSION_VARS["user_key"] = $user_key;
    $set_user_key = $user_key;
    $get_user_key = get_session_key("user_key");
  }
  
  function log_session() {
  }
  
  function get_session_key($key_name) {
    global $HTTP_SESSION_VARS;  
    return($HTTP_SESSION_VARS[$key_name]);
  }

<testing> 
I submit a Webpage that includes a value for "user_key".

<note> A session file is created in the subdirectory sessions. This
file's filename coincides with the reported cookie session id.
</note>

<processing> The function log_user_key(...) is called with a legal value
in response to my user input. 
</processing>

<verification> In response to the user's input I generate webpage that
reports the value that was saved. I report this value using the function
log_user_key().
</verficiation>

<failure> I submit another Webpage. This Webpage reports:
a) The registration of the variable "user_key" was apparently preserved.
How I know that? Because $registered_user_key is set to false, which
means that the body of the if (! sesson_is_registerd ...) {} wasn't
visited. 
b) I report the result of session_is_registered and it report 1 (i.e.
true).
c) get_session_key("user_key") does not return the value I previously
assigned to "user_key" using the log_user_key function.
</failure>

I checked the session file in the sessions/ subdirectory. It is empty.
Doesn't PHP's session manager keep its info in there? If it does, why
wasn't it written to the file? Doesn't the default files
session_save_handler take care of that? Or must I supply a custom
handler set to ensure that the values are saved?

TIA,

Elan

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to