Re: [PHP] Yet another session problem, with a twist.

2002-06-30 Thread Justin French

PHPLib has session functions, and was essentially what people used before
PHP4.  It will of course require a fair bit of work to port your scripts
across.

Personally I'd change to another host :)


Justin French


on 29/06/02 2:17 PM, Cysec ([EMAIL PROTECTED]) wrote:

 I have already scripted a site using PHP 4 and was at the point of uploading
 it to my client's chosen server (decided to go third party) when I discover,
 their server is running PHP3, launch is in five days, and I have 40+ pages
 using PHP4's session handling (session_start() etc.).  This would be a total
 pain to change throughout the site, so I was wondering if anyone knew of a
 script of functions that emulate PHP4's session handling.  I would love to
 be able to just update the server, and would have if it were one I was
 administrating, however I can't.  Any help would be vastly appreciated.
 
 


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




[PHP] yet another session problem

2002-04-24 Thread Richard Fox

I am testing user-handling of sessions (mysql database) and just do not understand 
this behavior. my SESSION table is created as 

CREATE TABLE SESSION (
  id varchar(32) NOT NULL default '',
  time timestamp(14) NOT NULL,
  user_id mediumint(8) NOT NULL default '-1',
  data text NOT NULL,
  PRIMARY KEY  (id)
) TYPE=MyISAM;

I have a main script index.php3

?php

require(./sessions.inc);

session_module_name(user);

session_set_save_handler(sess_open, sess_close,
   sess_read, sess_write, sess_remove, sess_gc);

session_start();

if (!isset($_SESSION['']))  {
   $_SESSION[''] = 1;
   print(br set );
   }


function increment() {
   $_SESSION['']++;
   echo br=.$_SESSION[''].br;
   }

function set_() {
   echo set br;
   $_SESSION[''] = 666;
   }


if (isset($_POST['MYVAR']))
   set_();
else
   increment();

echo a href=\$PHP_SELF\$PHP_SELF increment /Abr;
echo a href=\$PHP_SELF?MYVAR=3\$PHP_SELF register /A;

?

and sessions.inc:

?php

function session_table() {
   return(SESSION);
   }

function session_log($message) {
   if($file = fopen(/tmp/session.txt, a)) {
  fwrite($file, date(Y-m-d H:i:s ) . $message . \n);
  fclose($file);
  }
   }

function sess_open($path, $name) {
   session_log(session_open);
   return(true);
   }

function sess_close() {
   session_log(session_close);
   return(true);
   }

function sess_read($id) {
   session_log(session_read);
   $db = mysql_pconnect('localhost','mysqluser','password');
   if(!mysql_select_db('rfox_auth')) {
  session_log(session_read select database error: 
 . mysql_error());
  return();
  }
   $sql = select * from  . session_table()
  .  where id=' . $id . ';
   if(!$result = mysql_query($sql)) {
  session_log(MySQL error:  . mysql_error()
 .  with SQL:  . $sql);
  return();
  }
   if(mysql_num_rows($result)) {
  session_log(MySQL query returned  . mysql_num_rows($result)
 .  rows.);
  $row = mysql_fetch_assoc($result);
  session_log(session_read returned  . $row[data]);
  return($row[data]);
  }
   else {
  session_log(session_read found zero rows with SQL:  . $sql);
  return();
  }
   }

function sess_write($id, $data) {
   session_log(session_write);
   if(!mysql_select_db('rfox_auth')) {
  session_log(session_write select database error: 
 . mysql_error());
  return(false);
  }
   $sql = update  . session_table()
  .  set data = ' . addslashes($data) . ', time = null;
   $sql .=  where id=' . $id . ';
   if (!$result = mysql_query($sql)) {
  session_log(session_write error  . mysql_error()
 .  with SQL:  . $sql);
  return(false);
  }
   if (mysql_affected_rows()) {
  session_log(session_write update affected 
 . mysql_affected_rows() .  rows with SQL:  . $sql);
  return(true);
  }
   session_log(session_write updated zero rows with SQL:  . $sql);
   $sql = insert  . session_table()
  .  set data = ' . addslashes($data) . ', id = ' . $id . ';
   if(!$result = mysql_query($sql)) {
  session_log(session_write error  . mysql_error()
 .  with SQL:  . $sql);
  return(false);
  }
   else {
  session_log(session_write inserted with SQL:  . $sql);
  return(true);
  }
   }


function sess_remove($id)
   {
   session_log(session_remove);
   if(!mysql_select_db('rfox_auth'))
  {
  session_log(session_remove select database error: 
 . mysql_error());
  return(false);
  }
   $sql = delete  . session_table() .  where id=' . $id . ';
   if ($result = mysql_query($sql))
  {
  session_log(MySQL query delete worked.);
  return(true);
  }
   else
  {
  session_log(MySQL update error:  . mysql_error()
 .  with SQL:  . $sql);
  return(false);
  }
   }

function sess_gc($life)
   {
   session_log(session_gc);
   if (!mysql_select_db('rfox_auth')) {
  session_log(session_gc select database error:  . mysql_error());
  return(false);
  }
   $sql = delete from  . session_table() .  where time  '
  . date(YmdHis, time() - $life) . ';
   session_log(session_gc sql:  . $sql);
   if ($result = mysql_query($sql)) {
  session_log(session_gc deleted  . mysql_affected_rows()
 .  rows.);
  return(true);
  }
   else {
  session_log(session_gc error:  . mysql_error()
 .  with SQL:  . $sql);
  return(false);
  }
   }
?

I can see in the log file that session_write() is executed when I register . But 
there is a problem:

PROBLEM: When I register , there is no call to session_write() in the log file, 
and no data for  gets written to the database. 

Can you duplicate this behavior on your system? Do you have an explanation?

Thanks!

Rich