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:
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
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");
?>
Kann mir bitte jemand den Fehler lösen? Ich weiß nicht mehr so richtig weiter.
Danke
Holger
EDIT:
PHP-Tags sponsored by Goth
Kommentar