Specifications
LISTING 28.3 Continued
//echo $query;
$result = mysql_query($query);
if (!$result)
return false;
if (mysql_num_rows($result)<1)
return false;
if(mysql_result($result, 0, 0) == 1)
return ‘admin’;
else
return ‘normal’;
}
Previously with login functions, we have returned true if the login was successful and false
if it was not. In this case, we still return false if the login failed, but if it was successful we
return the user type, either ‘admin’ or ‘normal’. We check the user type by retrieving the
value stored in the admin column in the subscribers’ table, for a particular combination of
email address and password. If no results are returned, we return false. If a user is an admin-
istrator, this value will be 1 (true), and we return ‘admin’. Otherwise, we return ‘normal’.
Returning to the main line of execution, we register a session variable to keep track of who our
user is. This will either be $admin_user if she is an administrator, or $normal_user if she is a
regular user. Whichever one of these variables we set will contain the email address of the user.
To simplify checking for the email address of a user, we use the get_email() get email()
mentioned earlier.
This function is shown in Listing 28.5.
LISTING 28.5 get_email() function from mlm_fns.php—Returns the Email Address of the
Logged In User
function get_email()
{
global $normal_user;
global $admin_user;
if (session_is_registered(“normal_user”))
return $normal_user;
if (session_is_registered(“admin_user”))
return $admin_user;
return false;
}
Building a Mailing List Manager
C
HAPTER 28
28
BUILDING A
MAILING LIST
MANAGER
677
34 7842 CH28 3/6/01 3:46 PM Page 677