Hey ppl. Im currently working on a way to enhance my login system. Each user has a status... either Admin or Staff. When a user logs in a want them to get directed to a section relevant to thier status.
Example.:
If an admin logs in they will get directed to the admin section of the site... which is were all the administrative features are. However if a staff member logs in they get directed to the staff section.
(Obviously the admin section will have all the stuff the staff section has but with the admin tools).
My code:
<?php
if($Submit=="Login"){
session_start();
$statusCheck = check_login($HTTP_POST_VARS);
if ($statusCheck == "Admin" || $statusCheck == "Staff"){
session_register("statusCheck");
header("location: members.php");
}
}
?>
<?
function check_login($formdata) {
$dbhost = "";
$dbuser = "";
$dbpassword = "";
$db = "";
$form_data = trim_data($formdata);
$user = $form_data['username'];
$password = $form_data['password'];
$mysql = mysql_connect($dbhost, $dbuser, $dbpassword);
if(!$mysql) {
$error = "Cannot connect to Database Host";
return($error);
}
$mysqldb = mysql_select_db($db);
if(!$mysqldb) {
$error = "Cannot open Database";
return($error);
}
$myquery = "SELECT * FROM cph_members WHERE username = '" . $user . "' AND password = '" . crypt($password,"DWMXPHP") . "'";
$result = mysql_query($myquery);
if (!$result){
$error = "Cannot run Query";
return($error);
}
$numRows = mysql_num_rows($result);
if ($numRows < 1){
$error = '<font face="Palatino Linotype" color="#FF0000" size="2"><b>User name or password not recognised</b></font>';
return($error); }
$userRecord = mysql_fetch_array($result);
$status = $userRecord["status"];
return($status);
}
?>
If you have a look at the statusCheck variable, it sets the admins and the staff to the same header. What I want to do is set separet headers for the admin and staff.
I've tried altering it to this:
<?php
if($Submit=="Login"){
session_start();
$statusCheck = check_login($HTTP_POST_VARS);
if ($statusCheck == "Staff"){
session_register("statusCheck");
header("location: members.php");
if ($statusCheck == "Admin"){
session_register("statusCheck");
header("location: admin.php");
}
}
}
?>
The problem is that when I try and login I get redirected to the display.php page becuase no session is set! why? I've also tried using an elseif for admin instead of if, that that didnt work either... i got a parse error from it! Any suggestions? thx!