<?php
include('db.php');
function show_page($usertype)
{
//start a session
session_start();
if($usertype=="admin") //if user type is admin
{
//create a session for the flag that determines that
//the current user is allowed to visit the admin pages
//and set this to true
$_SESSION["AllowAdmin"] = true;
//redirect him/her to the admin page
header("Location: admin.php");
}
else
{
//create a session for the flag that determines that
//the current user is allowed to visit the user pages that requires login
//and set this to true
$_SESSION["AllowUser"] = true;
//redirect him/her to the userindex page
header("Location: userindex.php");
}
}
//check if there is a postback or a form is submitted
if(count($_POST) > 0)
{
//get the username and password from the post variables
$username = $_POST['Uname'];
$pword = $_POST['Pword'];
$query = "SELECT username,pword,usertype FROM user_info WHERE username = '$username' AND pword = '$pword'";
$result = mysql_query($query);
//count number of rows being retrieved
//if it has a record
if (mysql_num_rows($result) > 0)
{
$row = mysql_fetch_rows($result);//fetch the results
//check if it user and pass from the form vs. from the DB matches
if($username==$row[0] && $pword == $row[1])
{
show_page($row[2]);
}
}
}
?>
<form method="post">
Username: <input type="text" name="UName" /><br>
Password: <input type="password" name"PWord" /><br>
<input type="submit" value="Go" />