Specifications

This is the first script with any complexity to it that we have looked at in this application.
The script begins by including the applications function files and starting a session. (When the
user is registered, we will create his username as a session variable as we did in Chapter 20,
Using Session Control in PHP.)
Next, we validate the input data from the user. There are a number of conditions we must test
for. They are
Check that the form is filled out. We test this with a call to the function filled_out() as
follows:
if (!filled_out($HTTP_POST_VARS))
This function is one we have written ourselves. It is in the function library in the file
data_valid_fns.php. Well look at this function in a minute.
Check that the email address supplied is valid. We test this as follows:
if (valid_email($email))
Again, this is a function that weve written, which is in the data_valid_fns.php library.
Check that the two passwords the user has suggested are the same, as follows:
if ($passwd != $passwd2)
Check that the password is the appropriate length, as follows:
if (strlen($passwd)<6 || strlen($passwd) >16)
In our example, the password should be at least 6 characters long to make it harder to
guess, and fewer than 16 characters, so it will fit in the database.
The data validation functions we have used here, filled_out() and valid_email(),are
shown in Listing 24.7 and Listing 24.8, respectively.
LISTING 24.7 filled_out() Function from data_valid_fns.phpThis Function Checks That
the Form Has Been Filled Out
function filled_out($form_vars)
{
// test that each variable has a value
foreach ($form_vars as $key => $value)
{
if (!isset($key) || ($value == “”))
return false;
}
return true;
}
Building Practical PHP and MySQL Projects
P
ART V
510
30 7842 ch24 3/6/01 3:34 PM Page 510