[snip]
A site I'm working on requires a login screen where various individuals
will log into the site and add information for their various
departments.  Rather than setup a different script for each department, I
was hoping to create one script that would either accept or deny a login
based on the username/password stored in a database, then based on the
username/password - redirect the individuals browser to a URL.
[/snip]

You need to take the script below and place it into a seperate file with NO
OTHER INFORMATION. Your form action should state that this script is the
action and method should be POST. Modify this script for access levels and
redirect pages.
<?

//connect to and select database
if(!($dbconnect = mysql_pconnect("127.0.0.1", "user", "password"))){
        print("Failed to connect to database!\n");
        exit();
        }
if(!mysql_select_db("database", $dbconnect)){
        print("Failed to select database!\n");
        exit();
        }

//query to compare user to database
//user uses email addy in this instance
$quser = "SELECT email, password, accesslevel ";
$quser .= "FROM tblUser ";
$quser .= "WHERE email = '$email' ";
$quser .= "AND password = '$password' ";

if(!($dbresult = mysql_query($quser, $dbconnect))){
        print("MySQL reports: " . mysql_error() . "\n");
        exit();
        }

//start session
session_start();
//set session variables so that they can be compared on latter pages
//preeventing a person from going directly to a page without being
//logged in
session_register("emailid");
session_register("level");

$dbuser = mysql_fetch_object($dbresult);
$emailid = $dbuser->email;
$level = $dbuser->accesslevel; //

//send the user to a page based on their user level

switch($level)
{
        case "level1":
        header("Location: level1.php"); exit;
        break;
        case "level2":
        header("Location: level2.php"); exit;
        break;
        case "level3":
        header("Location: level.php"); exit;
        break;
        case "level4":
        header("Location: level4.php"); exit;
        break;
        case "level5":
        header("Location: level5.php"); exit;
        break;
        default:
        header("Location: loginfail.php"); exit;
}

?>

HTH!

Jay



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to