Specifications
LISTING 24.8 valid_email() Function from data_valid_fns.php—This Function Checks
Whether an Email Address Is Valid
function valid_email($address)
{
// check an email address is possibly valid
if (ereg(“^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$”, $address))
return true;
else
return false;
}
The function filled_out() expects to be passed an array of variables—in general, this will be
the $HTTP_POST_VARS or $HTTP_GET_VARS arrays. It will check whether they are all filled out,
and return true if they are and false if they are not.
The valid_email() function uses the regular expression we developed in Chapter 4, “String
Manipulation and Regular Expressions,” for validating email addresses. It returns true if an
address appears valid, and false if it does not.
After we’ve validated the input data, we can actually try and register the user. If you look back
at Listing 24.6, you’ll see that we do this as follows:
$reg_result = register($username, $email, $passwd);
if ($reg_result == “true”)
{
// register session variable
$valid_user = $username;
session_register(“valid_user”);
// provide link to members page
do_html_header(“Registration successful”);
echo “Your registration was successful. Go to the members page “
.”to start setting up your bookmarks!”;
do_HTML_URL(“member.php”, “Go to members page”);
}
As you can see, we are calling the register() function with the username, email address, and
password that were entered. If this succeeds, we register the username as a session variable and
provide the user with a link to the main members page. This is the output shown in Figure 24.5.
Building User Authentication and Personalization
C
HAPTER 24
24
AUTHENTICATION
AND
PERSONALIZATION
511
30 7842 ch24 3/6/01 3:34 PM Page 511










