[PHP] session_set_save_handler

2003-09-10 Thread Chris Boget
If the above is called to set user defined session handling functions,
is there a way to reset it back to the default PHP session handling?
I tried calling it with no arguments but got an error.  I've looked in the
docs but it doesn't say anything about resetting the handlers.

Does anyone know if/how this can be done?

thnx,
Chris

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] session_set_save_handler problem

2003-03-06 Thread Duncan
Hi,

i just tried the session_set_save_handler script from Sterling Hughes
PHP Cookbook, which allows to save the session in a MySQL database.
However, i ran into a problem:
The script works just fine and also saves the session in the database,
but it doesn't update the value of the saved data.
I browsed google for additional examples, but only to find out, that the
exact same problem appeared.
So, my guess is, that my script has some kind of logical error, but i am
unable to spot it.
Any help is more than welcome (regarding my starting headache ;) )
Here is the script:

If the session_set_save_handler function is commented (as seen below),
then the script starts the session and continues to display the
increasing $counter variable with every page reload.
However, once you uncomment the session_set_save_handler function, the
session gets saved in the MySQL database, but the counter variable won't
increase and always stays at 1. (as i said, i tried this with several
scripts already, but all resulted in the same problem)
So, i think the problem is either in the on_session_write() part, where
the value doesn't increase, or -as already pointed out- i am having a
logical error with the $counter variable.
...just to clarify: $counter++; also means that it should be increased
in the MySQL database, right? Or would i have to do s.th. else to update
the session values in the MySQL database?
The script:

?
function on_session_start($save_path, $session_name)
{
// nothing
}
function on_session_end()
{

// nothing

}
function on_session_read($key)
{
$db = mysql_connect(DB_HOST,DB_USER,DB_PASS);
mysql_select_db(DB_DATABASE);
if ($db)
{
$query = mysql_query('SELECT session_data FROM sessions WHERE
session_id='.$key.' AND session_expiration  now()');
$row = mysql_fetch_row($query);
}
return $row[0];
mysql_close();
}
function on_session_write($key, $val)
{

$val = addslashes($val);
$db = mysql_connect(DB_HOST,DB_USER,DB_PASS);
mysql_select_db(DB_DATABASE);
if ($db)
{
$query = mysql_query('INSERT INTO sessions VALUES('.$key.',
'.$val.', now() + 3600)');
if (!$query)
$queryb = mysql_query('UPDATE sessions SET 
session_data='.$val.',
session_expiration=now()+3600 WHERE session_id='.$key.'');
if (!$queryb)
die(sprintf($val - $key));
}
mysql_close();
}
function on_session_destroy($key)
{
$db = mysql_connect(DB_HOST,DB_USER,DB_PASS);
mysql_select_db(DB_DATABASE);
if ($db)
{
mysql_query('DELETE FROM sessions WHERE session_id='.$key.'');
}
mysql_close();
}
function on_session_gc($max_lifetime)
{
$db = mysql_connect(DB_HOST,DB_USER,DB_PASS);
mysql_select_db(DB_DATABASE);
if ($db)
{
mysql_query('DELETE FROM sessions WHERE session_expiration  now()');
}
mysql_close();
}
/*
session_set_save_handler('on_session_start',   'on_session_end',
 'on_session_read',
'on_session_write',
 'on_session_destroy', 
'on_session_gc');
*/
session_start();

session_register('counter');

$counter++;

print $counter;

//session_destroy();

?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] session_set_save_handler problem

2003-03-06 Thread Duncan
AHA!

I found the problem:

session_expiration is an unsigned int(11) field type and so
session_expiration  now()
always results in no match, even when it should be in the 
on_session_read() function.
...now i need to make sure, that the now() gets the same value type, right?
...any ideas?

Thanks,
Duncan
Duncan wrote:

Hi,

i just tried the session_set_save_handler script from Sterling Hughes
PHP Cookbook, which allows to save the session in a MySQL database.
However, i ran into a problem:
The script works just fine and also saves the session in the database,
but it doesn't update the value of the saved data.
I browsed google for additional examples, but only to find out, that the
exact same problem appeared.
So, my guess is, that my script has some kind of logical error, but i am
unable to spot it.
Any help is more than welcome (regarding my starting headache ;) )
Here is the script:

If the session_set_save_handler function is commented (as seen below),
then the script starts the session and continues to display the
increasing $counter variable with every page reload.
However, once you uncomment the session_set_save_handler function, the
session gets saved in the MySQL database, but the counter variable won't
increase and always stays at 1. (as i said, i tried this with several
scripts already, but all resulted in the same problem)
So, i think the problem is either in the on_session_write() part, where
the value doesn't increase, or -as already pointed out- i am having a
logical error with the $counter variable.
...just to clarify: $counter++; also means that it should be increased
in the MySQL database, right? Or would i have to do s.th. else to update
the session values in the MySQL database?
The script:

?
function on_session_start($save_path, $session_name)
{
// nothing
}
function on_session_end()
{

// nothing

}

function on_session_read($key)
{
$db = mysql_connect(DB_HOST,DB_USER,DB_PASS);
mysql_select_db(DB_DATABASE);
if ($db)
{
$query = mysql_query('SELECT session_data FROM sessions WHERE
session_id='.$key.' AND session_expiration  now()');
$row = mysql_fetch_row($query);
}
return $row[0];
mysql_close();
}
function on_session_write($key, $val)
{

$val = addslashes($val);
$db = mysql_connect(DB_HOST,DB_USER,DB_PASS);
mysql_select_db(DB_DATABASE);
if ($db)
{
$query = mysql_query('INSERT INTO sessions VALUES('.$key.',
'.$val.', now() + 3600)');
if (!$query)
$queryb = mysql_query('UPDATE sessions SET 
session_data='.$val.',
session_expiration=now()+3600 WHERE session_id='.$key.'');
if (!$queryb)
die(sprintf($val - $key));
}
mysql_close();
}

function on_session_destroy($key)
{
$db = mysql_connect(DB_HOST,DB_USER,DB_PASS);
mysql_select_db(DB_DATABASE);
if ($db)
{
mysql_query('DELETE FROM sessions WHERE session_id='.$key.'');
}
mysql_close();
}
function on_session_gc($max_lifetime)
{
$db = mysql_connect(DB_HOST,DB_USER,DB_PASS);
mysql_select_db(DB_DATABASE);
if ($db)
{
mysql_query('DELETE FROM sessions WHERE session_expiration  
now()');
}
mysql_close();
}

/*
session_set_save_handler('on_session_start',   'on_session_end',
 'on_session_read','on_session_write',
 'on_session_destroy', 'on_session_gc');
*/
session_start();

session_register('counter');

$counter++;

print $counter;

//session_destroy();
   
?




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] session_set_save_handler()

2001-11-29 Thread phantom

I am trying to set up a session setup that saves session data to a mysql
database.

I have gone into php.ini and set session.save_handler to user.

I call the following include file up using
session_set_save_handler(open, close, read, write, destroy,
gc);

(of course I have labeled each function correctly as they appear in my
include file, just too lazy to write it all out here).

When I run the page this is on, I get a parse error at the line where
function session_open is in the include file (see below)

Any idea why?  Thanks

I am modeling this word for word from a example found at:
http://www.onlamp.com/pub/a/php/2001/05/10/sessions.html?page=1 (pages 1
thru 3)

my session include file:

   ?

   // Session Table

   $sess_table = Sessions;

   // Retrieve the session maximum lifetime (found in
php.ini)

   $lifetime = get_cfg_var(session.gc_maxlifetime);

   //=
   // function: mysql_session_open()
   // purpose: Opens a persistent server connection and
selects
   the
   //database.
   //=

   mysql_session_open($session_path, $session_name) {
// parse error on this line;

 mysql_pconnect(localhost, mysql_username,
mysql_password)
or die(Can't connect to MySQL server! );

 mysql_select_db(sessions_database)
or die(Can't select MySQL sessions
database);

   } // end mysql_session_open()

   //=
   // function: mysql_session_close()
   // purpose: Doesn't actually do anything since the
server
   connection is
   //persistent. Keep in mind that although this
function
   //doesn't do anything in my particular
implementation, I
   //still must define it.
   //=

   mysql_session_close() {

 return 1;

   } // end mysql_session_close()

   //=
   // function: mysql_session_select()
   // purpose: Reads the session data from the database
   //=

   mysql_session_select($SID) {

 GLOBAL $sess_db;
 GLOBAL $sess_table;

 $query = SELECT value FROM $sess_table
 WHERE SID = '$SID' AND
 expiration  . time();

 $result = mysql_query($query);

   } // end mysql_session_select()

   //=
   // function: mysql_session_write()
   // purpose: This function writes the session data to
the
   database. If that SID // already exists, then the
existing
   data will be updated.
   //=

   mysql_session_write($SID, $value) {

 GLOBAL $sess_db;
 GLOBAL $sess_table;
 GLOBAL $lifetime;

 $expiration = time() + $lifetime;

 $query = INSERT INTO $sess_table
 VALUES('$SID', '$expiration', '$value');

 $result = mysql_query($query, $sess_db);

 if (! $result) :

  $query = UPDATE $sess_table SET
  expiration = '$expiration',
  value = '$value' WHERE
  SID = '$SID' AND expiration . time();

  $result = mysql_query($query, $sess_db);

 endif;

   } // end mysql_session_write()

   //=
   // function: mysql_session_destroy()
   // purpose: deletes all session information having
input SID
   (only one row)
   //=

   mysql_session_destroy($sessionID) {

 GLOBAL $sess_table;

 $query = DELETE FROM $sess_table
 WHERE SID = '$sessionID';
 $result = mysql_query($query);

   } // end mysql_session_destroy()

   //=
   // function: mysql_session_garbage_collect()
   // purpose: deletes all sessions that have expired.
   //=

   mysql_session_garbage_collect($lifetime) {

 GLOBAL $sess_table;

 $query = DELETE FROM $sess_table
 WHERE sess_expiration  .time() - $lifetime;
 $result = mysql_query($query);

 

[PHP] session_set_save_handler question

2001-09-24 Thread Bob Bowker

Hi --

No luck finding an answer to this ... can class methods be registered as 
the user functions with session_set_save_handler() -- or do I have to 
create a wrapper outside the class to call the class functions?  Using 
4.0.3pl1 ...

Thanks --

Bob.


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

2001-07-30 Thread Wendy Roseberry

We have several small applications that have been using the built-in session
functions from php for quite sometime.  Recently, I have started using the
session_set_save_handler in 3 of those applications.  Even though the
documentation on php.net says,

 Note: You must set the configuration option session.save_handler to user
in your php.ini file for session_set_save_handler() to take effect.,

I have found that I can still use my customer save_handler with the
session.save_handler in the php.ini being set to 'files'.  Since I
implemented this function, we noticed that our other applications that do
not call session_set_save_handler started having the following error:
Fatal error: Failed to initialize session module in backend.php on line 27

Warning: Failed to write session data (user). Please verify that the current
setting of session.save_path is correct (/tmp) in backend.php on line 0

line 27 of backend.php is a simple session_start();

The /tmp is not full and is fully writable.  It seems that when the 3 custom
session applications are in use, that this error starts popping up in other
session applications.

Is my call to a session_set_save_handler somehow changing the php.ini for
a bit?  It's like the custom session application is setting the
session.save_handler to 'user' for all other sessions.

Any comments would be welcome.

Thanks,

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