Location: PHPKode > scripts > alarisMenu > alarismenu/alarisAdmin/validate_user.php
<?php require_once("alaris_main_fns.php");

# Prompt for username and password to check if
# they are set
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #

if(!isset($_REQUEST["username"]) OR !isset($_REQUEST["password"])){
    // Error
    check_valid_user();
    exit;
}

# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #


# Checking if the username and password are correct
# and then redirect to the admin area

else {
#   Connecting to the database to retrieve the info
	db_connect();
	$usersquery=mysql_query("SELECT username FROM alaris_users") or die ("The query on the number of users didn't work.");
	if (mysql_num_rows($usersquery) == "0") {
		print "There are no users registered!";
		exit();
	}
	
#	If $username and $passwd are set, match data against users table
	$query=mysql_query("SELECT * FROM alaris_users WHERE username = '$username' AND password = '$password'") or die ("For some reason the script wasn't able to check the username/password.");

#	Check if there is only one entry
	if (mysql_num_rows($query) == 1) {
	
	session_start();

	# Declaring some varibles
	$valid_user = $username;
	$id = md5(uniqid(microtime(), 1)) . getmypid(); // creating a unique identifier
	$data = mysql_fetch_object ($query);
	$rowid = $data->user_id;
	$fname = $data->firstname;
	$lname = $data->lastname;
	
	# Declaring session variables
	session_register("valid_user");
	session_register("id");
	session_register("rowid");
	session_register("fname");
	session_register("lname");
	
	Header("Location: ./alarisAdmin.php?$id");
	}
# ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #

# If there is a problem we redirect to login page again
# and then display an error page.

     else{
     Header("Location: ./login.php?loginerror=true");
  }
}
?>
Return current item: alarisMenu