I'm starting to learn about sessions, and I copied to following script from a book. But I keep getting the following error:
Parse error: syntax error, unexpected T_FUNCTION in C:\Apache2\Apache2\htdocs\session.php on line 16
Any help? (Line 16 is where I define the first function. However, if I delete that function I get the same error for the next function - so it seems to be functions in general.)
PHP Code:
<? php
/*
* mysql_session_open()
*/
function mysql_session_open($session_path, $session_name) {
mysql_pconnect("localhost")
or die ("Can't connect to MySQL server. ");
mysql_select_db("sessions")
or die ("Can't select MySQL database. ");
} //end mysql_session_open()
/*
* mysql_session_close()
*/
function mysql_session_close() {
return 1;
} //end mysel_session_close()
/*
* mysql_session_select()
*/
function mysql_session_select($SID) {
$query = "SELECT value FROM sessioninfo WHERE SID = '$SID' AND expiration > ". time();
$result = mysql_query($query);
if (mysql_num_rows($result)) {
$row=mysql_fetch_assoc($result);
$value = $row['value'];
return $value;
} else {
return "";
}
} //end mysql_session_select()
/*
* mysql_session_write()
*/
function mysql_session_write($SID, $value) {
$lifetime = get_cfg_var("session.gc.maxlifetime");
$expiration = time() + $lifetime;
$query = "INSERT INTO sessioninfo VALUES('$SID', '$expiration', '$value')";
$result = mysql_query($query);
if (! $result) {
$query = "UPDATE sessioninfo SET expiration = '$expiration' value = '$value' WHERE SID = '$SID' AND expiration > ". time();
$result = mysql_query($query);
}
} //end mysql_session_write()
/*
* mysql_session_destroy()
*/
function mysql_session_destroy($SID) {
$query = "DELETE FROM sessioninfo WHERE SID = '$SID'";
$result = mysql_query($query);
} // end mysql_session_destroy()
/*
* mysql_session_garbage_collect()
*/
function mysql_session_garbage_collect($lifetime) {
$query = "DELETE FROM sessioninfo WHERE sess_expiration < ".time() - $lifetime;
$result = mysql_query($query);
return mysql_affected_rows($result)
} //end mysql_session_garbage_collect()
?>
|