Sessionverwaltung mit MySQL; Problem mit sessionClose

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Sessionverwaltung mit MySQL; Problem mit sessionClose

    Hallo,

    ich habe aus dem Buch "Web Datenbanke Applikationen" von OReilly die datenbankbasierte Sessionverwaltung implementiert und erhalte immer die Warnung :"Warning: Missing argument 1 for sessionclose() in G:\\001_homepage\includes\mysql_sessions.inc on line 163". Die Website wird normal dargestellt - nur die Warnung ist unten zu sehen.

    Die Zeile 163 lautet folgendermaßen:

    function sessionClose($sess_id)

    Hier das ganze Skript:


    PHP-Code:
    <?php
    /*
    Source code example for Web Database Applications

    Unless otherwise stated, the source code distributed with this book can be
    redistributed in source or binary form so long as an acknowledgment appears
    in derived source files.
    The citation should list that the code comes from Hugh E.
    Williams and David Lane, "Web Database Application with PHP and MySQL"
    published by O'Reilly & Associates.
    This code is under copyright and cannot be included in any other book,
    publication, or educational product without permission from O'Reilly &
    Associates.
    No warranty is attached; we cannot take responsibility for errors or fitness
    for use.
    */

    include("error.inc");
    include(
    "db.inc");

    // Returns current time as a number.
    // Used for recording the last session access.
    //
    function getMicroTime()
    {
      
    // microtime() returns the number of seconds 
      // since 0:00:00 January 1, 1970 GMT as a
      // microsecond part and a second part.
      // eg: 0.08344800 1000952237
      // Convert the two parts into an array
      
    $mtime explode(" "microtime());

      
    // Return the addition of the two parts 
      // eg: 1000952237.08344800
      
    return($mtime[1] + $mtime[0]);
    }  

    // The database connection
    global $connection;

    // The global variable that holds the table name
    global $session_table;


    // The session open handler called by PHP whenever
    // a session is initialized. Always returns true.
    //
    function sessionOpen($database_name$table_name)
    {

      
    // Save the database name in a global variable
      
    global $connection;
      global 
    $hostName;
      global 
    $username;
      global 
    $password;
      global 
    $session_table;

      if (!(
    $connection = @ mysql_pconnect($hostName
                                           
    $username
                                           
    $password)))
         
    showerror();

      if (!
    mysql_select_db($database_name$connection))
         
    showerror();

      
    // Save the table name in a global variable
      
    $session_table $table_name;

      return 
    true;
    }

    // This function is called whenever a session_start() 
    // call is made and reads the session variables
    // Returns "" when a session is not found
    //         (serialized)string - session exists
    //
    function sessionRead($sess_id)
    {
      
    // Access the DBMS connection
      
    global $connection;

      
    // Access the global variable that holds the name
      // of the table that holds the session variables
      
    global $session_table;

      
    // Formulate a query to find the session 
      // identified by $sess_id
      
    $search_query 
        
    "SELECT * FROM $session_table 
          WHERE session_id = '
    $sess_id'";

      
    // Execute the query
      
    if (!($result = @ mysql_query($search_query
                                    
    $connection)))
         
    showerror();                                

      if(
    mysql_num_rows($result) == 0)
        
    // No session found - return an empty string
        
    return "";
      else
      {
        
    // Found a session - return the serialized string
        
    $row mysql_fetch_array($result);
        return 
    $row["session_variable"];
      }
    }


    // This function is called when a session is initialized
    // with a session_start() call, when variables are
    // registered or unregistered, and when session variables
    // are modified. Returns true on success.
    //
    function sessionWrite($sess_id$val)
    {
      global 
    $connection;
      global 
    $session_table;

      
    $time_stamp getMicroTime();

      
    $search_query 
        
    "SELECT session_id FROM $session_table
           WHERE session_id = '
    $sess_id'";

      
    // Execute the query
      
    if (!($result = @ mysql_query($search_query
                                    
    $connection)))
         
    showerror();

      if(
    mysql_num_rows($result) == 0)
      {
         
    // No session found, insert a new one
         
    $insert_query 
             
    "INSERT INTO $session_table 
              (session_id, session_variable, last_accessed)
               VALUES ('
    $sess_id', '$val', $time_stamp)";

         if (!
    mysql_query($insert_query
                          
    $connection))
            
    showerror();
      }
      else 
      {
         
    // Existing session found - Update the 
         // session variables
         
    $update_query 
           
    "UPDATE $session_table 
            SET session_variable = '
    $val',
                last_accessed = 
    $time_stamp
            WHERE session_id = '
    $sess_id'";

         if (!
    mysql_query($update_query
                          
    $connection))
            
    showerror();
      }
      return 
    true;
    }


    // This function is executed on shutdown of the session. 
    // Always returns true.
    //          Die folgende Zeile ist die 163
    function sessionClose($sess_id)
    {
        return 
    true;
    }  


    // This is called whenever the session_destroy() 
    // function call is made. Returns true if the session
    // has successfully been deleted.
    //
    function sessionDestroy($sess_id)
    {
      global 
    $connection;
      global 
    $session_table;

      
    $delete_query 
        
    "DELETE FROM $session_table
          WHERE session_id = '
    $sess_id'";

      if (!(
    $result = @ mysql_query($delete_query
                                    
    $connection)))
         
    showerror();

      return 
    true;
    }


    // This function is called on a session's start up with
    // the probability specified in session.gc_probability.
    // Performs garbage collection by removing all sessions 
    // that haven't been updated in the last $max_lifetime
    // seconds as set in session.gc_maxlifetime.
    // Returns true if the DELETE query succeeded.
    //
    function sessionGC($max_lifetime)
    {
      global 
    $connection;
      global 
    $session_table;

      
    $time_stamp getMicroTime();

      
    $delete_query 
        
    "DELETE FROM $session_table
          WHERE last_accessed < (
    $time_stamp - $max_lifetime)";

      if (!(
    $result = @ mysql_query($delete_query,
                                    
    $connection)))
         
    showerror();

      return 
    true;
    }


    // Call to register user call back functions.

    session_set_save_handler("sessionOpen"
                             
    "sessionClose"
                             
    "sessionRead"
                             
    "sessionWrite"
                             
    "sessionDestroy"
                             
    "sessionGC");

    ?>
    Der Übertrag der Sessiondaten in die Datenbankfelder funktioniert.

    Kann mir bitte jemand den Fehler lösen? Ich weiß nicht mehr so richtig weiter.

    Danke

    Holger

    EDIT:
    PHP-Tags sponsored by Goth
    Zuletzt geändert von goth; 16.06.2004, 15:45.

  • #2
    Lass einfach den Parameter weg ... dann sollte es auch ohne Meldung gehen ... !

    Außerdem solltest Du .. wenn Du schon unmengen von Quellcode postest .. zumindest PHP-Tags verwenden ... !
    Zuletzt geändert von goth; 16.06.2004, 15:45.
    carpe noctem

    [color=blue]Bitte keine Fragen per EMail ... im Forum haben alle was davon ... und ich beantworte EMail-Fragen von Foren-Mitgliedern in der Regel eh nicht![/color]
    [color=red]Hinweis: Ich bin weder Mitglied noch Angestellter von ebiz-consult! Alles was ich hier von mir gebe tue ich in eigener Verantwortung![/color]

    Kommentar


    • #3
      Hi

      Ich habe dieses Buch auch und möchte diesselbe Routine benutzen, habe aber auch noch ein paar problemchen... Der Übertrag der Sessiondaten in die Datenbankfelder funktioniert.

      1. Die Garbage-Collection Routine scheint nicht zu funktionnieren. Die Sessiondaten werden nicht gelöscht.

      2. Seit ich dieses Script ausprobiert habe, geben andere Scripts mit der normalen Routine biem aufruf von session_start() folgenden fehler aus.
      session_start(): Failed to initialize storage module: user (path: /tmp)
      Was daran sehr verwirrend ist, ist dass der fehler nicht immer passiert! Ich kann ein Script mit der normalen Routine mehrmals aufrufen und es scheint erst mal alles in Ordnung zu sein... bis irgendwann der Fehler doch noch passiert.

      3. Auf Seite 575 im Buch heisst es, dass einige Parameter noch angepasst werden müssen:
      session.save_handler = user
      session.save_path = winestore
      session.name = PHPSESSION
      Ich habe dafür im geposteten Code am Anfang, nach den includes das hinzugefügt:
      PHP-Code:
      ini_set("session.save_handler","user");
      ini_set("session.save_path","winestore");
      ini_set("session.name","PHPSESSION"); 
      Macht man das so? Wie gesagt, der Übertrag der Sessiondaten in die Datenbankfelder funktioniert. ini_set gilt ja nur solange der Script ausgeführt wird. Warum bekomme ich bei den Scripts mit der normalen Routine "Failed to initialize storage module: user (path: /tmp)" zu sehen? Gibt's da überhaupt einen Zusammenhang?

      Kommentar

      Lädt...
      X