Specifications

FIGURE 20.6
After the user has logged in, she can access the members areas.
Lets look at the code for this application. Most of the code is in authmain.php. This script can
be seen in Listing 20.4. We will go through it bit by bit.
LISTING 20.4 authmain.phpThe Main Part of the Authentication Application
<?
session_start();
if ($userid && $password)
{
// if the user has just tried to log in
$db_conn = mysql_connect(“localhost”, “webauth”, “webauth”);
mysql_select_db(“auth”, $db_conn);
$query = “select * from auth “
.”where name=’$userid’ “
.” and pass=password(‘$password’)”;
$result = mysql_query($query, $db_conn);
if (mysql_num_rows($result) >0 )
{
// if they are in the database register the user id
$valid_user = $userid;
session_register(“valid_user”);
}
}
?>
<html>
Advanced PHP Techniques
P
ART IV
440
25 7842 CH20 3/6/01 3:42 PM Page 440