Re: [PHP] Custom Session Func?

2001-05-16 Thread Chris Lee

common mistake, your session_register() is before you assign the variable, you must 
have it after. Ive done this myself. oi.

  session_start();  
  if ( ! session_is_registered(user_key) ) {
$user_key = dummy;
session_register(user_key);
  }  

I'll include my session file. this will allways set $SID and will also allow you to 
transfer session's across multiple domains. handy.  somesites dont want to fork the 
money out to purchase their own ssl certificates, so we transfer them to our server 
where they can use our certificate (different domain obviously).

?php
 include_once('time.egn');

 if ( isset($HTTP_COOKIE_VARS['PHPSESSID']) )
 {
  if ( isset($HTTP_GET_VARS['PHPSESSID']) )
   $new_sessid = $HTTP_GET_VARS['PHPSESSID'];
  if ( isset($HTTP_POST_VARS['PHPSESSID']) )
   $new_sessid = $HTTP_POST_VARS['PHPSESSID'];

  if ( isset($new_sessid) )
   session_id($new_sessid);
 }

 session_start();

 if (!isset($HTTP_SESSION_VARS['SessionID']))
 {
  $SessionID = mtime();
  session_register('SessionID');
 }

 $PHPSESSID = session_id();
 $SID = PHPSESSID=$PHPSESSID;

?

-- 

 Chris Lee
 [EMAIL PROTECTED]



Elan [EMAIL PROTECTED] wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
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]



--
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]




RE: [PHP] Custom Session Func?

2001-05-16 Thread Johnson, Kirk

Chris, is this requirement spelled out in the manual anywhere? I have never
seen any effect of the order of calling session_register() and assigning a
value in my own code.  In fact, I almost always register a variable before
assigning a value.

Just curious.

Kirk

 -Original Message-
 From: Chris Lee [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, May 16, 2001 6:58 AM
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] Custom Session Func?
 
 
 common mistake, your session_register() is before you assign 
 the variable, you must have it after. Ive done this myself. oi.
 
   session_start();  
   if ( ! session_is_registered(user_key) ) {
 $user_key = dummy;
 session_register(user_key);
   }  

[major snippage] 

-- 
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]