Specifications

$result = mysql_query(“insert into user values
(‘$username’, password(‘$password’), ‘$email’)”);
if (!$result)
return “Could not register you in database - please try again later.”;
return true;
}
There is nothing particularly new in this functionit connects to the database we set up ear-
lier. If the username selected is taken, or the database cannot be updated, it will return false.
Otherwise, it will update the database and return true.
One thing to note is that we are performing the actual database connection with a function we
have written, called db_connect(). This function simply provides a single location that con-
tains the username and password to connect to the database. That way, if we change the data-
base password, we only need to change one file in our application. The function is shown in
Listing 24.10.
LISTING 24.10 db_connect() Function from db_fns.phpThis Function Connects to the
MySQL Database
function db_connect()
{
$result = mysql_pconnect(“localhost”, “bm_user”, “password”);
if (!$result)
return false;
if (!mysql_select_db(“bookmarks”))
return false;
return $result;
}
When users are registered, they can log in and out using the regular login and logout pages.
Well build these next.
Logging In
If users type their details into the form at login.php (see Figure 24.3) and submit it, they will
be taken to the script called member.php. This script will log them in if they have come from
this form. It will also display any relevant bookmarks to users who are logged in. It is the cen-
ter of the rest of the application. This script is shown in Listing 24.11.
Building User Authentication and Personalization
C
HAPTER 24
24
AUTHENTICATION
AND
PERSONALIZATION
513
LISTING 24.9 Continued
30 7842 ch24 3/6/01 3:34 PM Page 513