Hayley, Thanks this is what I came up with before reading your reply. I will look at your reply some more and see if I can make some improvements.
<?php
session_start();
if ($logOut) {
unset($_SESSION);
session_destroy();
echo "You have Logged out!<br>";
echo "<a href="index.php">Return to the site</a>";
exit;
}
if (isset($PHP_AUTH_USER)) {
// If non-empty, check the database for matches
// connect to MySQL
$db = mysql_connect("localhost", "username", "password");
mysql_select_db("addressbook",$db);
// Formulate the query
$sql = "SELECT * FROM address WHERE email='$PHP_AUTH_USER' and password='$PHP_AUTH_PW'";
// Execute the query and put results in $result
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
// Get number of rows in $result. 0 if invalid, 1 if valid.
$num = mysql_numrows($result);
if ($num != "0") {
session_start();
$_SESSION["userid"] = $myrow["id"];
//echo "$_SESSION[userid]";
//set cookie
} else {
$errorMsg = "<center>n<font color=red>Your user name or password was incorrect.<br><br>n";
include("login.inc");
exit;
}
}
if (!isset($_SESSION["userid"])) {
$errorMsg = "";
include("login.inc");
exit;
}
?>