");
print(mysql_error());
die();
}
}
// http_start() is a utility functin that puts out the first few
// lines of an HTML page. $title is used as the title of the
// page and also as a centered headline. After calling this,
// you should output the actual content of the page.
function http_start($title) {
print("\n
\n");
print("$title\n");
print("\n\n");
print("$title
\n");
}
// http_finish() is a utility function that puts out the last
// few lines of an HTML page -- the part that comes after the content.
function http_finish() {
print("\n");
print("\n");
}
// Create a session by storing $name in the database table named
// sessiondata, which has columns named sid, name, and visits.
// $name is inserted into the database. The number of visits will
// be automatically set to zero. The session identifier, sid,
// is generated automatically. The value of sid is returned as
// the value of the function. If there is any error, the script
// is terminated, so if this function returns, you can assume
// that the session has been created successfullly.
function createSession($name) {
$query = "INSERT into sessiondata (name) VALUES ('$name')";
if (mysql_query($query))
return mysql_insert_id();
else {
print("Sorry, there was a database error:
");
print(mysql_error());
die();
}
}
// Search in the database table named sessiondata for a row with
// sid equal to $sid. If no error occurs, the name and visits from
// the database are stored in GLOBAL variables named $name and $visits.
// THIS ROUTINE ALSO TAKES CARE OF ADDING ONE TO THE NUMBER OF VISITS.
// If an error occurs, the script is terminated, so if this function
// returns, you can assume that the variables $name and $visits have
// been properly set.
function getUserData($sid) {
global $name, $visits;
$query = "SELECT * from sessiondata where sid='$sid'";
if ($result = mysql_query($query)) {
if (mysql_num_rows($result) == 1) {
$row = mysql_fetch_array($result);
$name = $row['name'];
$visits = $row['visits'] + 1;
$query = "UPDATE sessiondata set visits=visits+1 where sid='$sid'";
mysql_query($query);
}
else {
print("Sorry, my database seems to be corrupt.");
die();
}
}
else {
print("Sorry, there was a database error:
");
print(mysql_error());
die();
}
}
?>