|
|
|
|
| Tutorial |
Chapter 4 Web Application Concepts
$result = mysql_db_query($sess_mysql[“db”], “REPLACE INTO
➥”.$sess_mysql[“table”].”VALUES (‘$sess_id’,‘$val’, null)”)
➥or die(mysql_error());
return(true);
}
function sess_mysql_destroy($sess_id)
{
global $sess_mysql;
// Delete from the MySQL table all data for the session $sess_id
$result = mysql_db_query($sess_mysql[“db”], “DELETE FROM
➥“.$sess_mysql[“table”].” WHERE id = ‘$sess_id’”) or die(mysql_error());
return(true);
}
function sess_mysql_gc($max_lifetime)
{
global $sess_mysql;
// Old values are values with a Unix less than now - $max_lifetime
$old = time() - $max_lifetime;
// Delete old values from the MySQL session table
$result = mysql_db_query($sess_mysql[“db”], “DELETE FROM
➥“.$sess_mysql[“table”].” WHERE UNIX_TIMESTAMP(t_stamp) < $old”) or
➥die(mysql_error());
return(true);
}
/*
* Basic Example: Registering above functions with session_set_save_handler()
*
$foo = 10;
session_set_save_handler(“sess_mysql_open”, “”, “sess_mysql_read”,
➥”sess_mysql_write”, “sess_mysql_destroy”, “sess_mysql_gc”);
session_start();
session_register(“foo”);
echo “foo: $foo”;
$foo++;
*
*/
Listing 4.2 Continued
|
|
|
|
|
|
| Link Partners: Asia florist, Flowers to India, Hong kong flowers, Site submit, Cheap web hosting, China florist, Japan florist |
|