Forums

This topic is locked

MX2004 Edit "log in user" to redirect users

Posted 09 Nov 2003 14:25:38
1
has voted
09 Nov 2003 14:25:38 Jon Webb posted:
So MX2004 has a nice "log in user" behaviour for PHP. Now, i have edited it so that different users go to different pages. My problem is that when a user logs in they are sent to "login failed .php" and the second attempt works perfectly (they are sent to admin.php or client.php).
Can anyone tell me how to stop the first failure?????

Heres the code (above my form)...
// start of PHP (with require(connect.php)
session_start();
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($accesscheck)) {
$GLOBALS['PrevUrl'] = $accesscheck;
session_register('PrevUrl');
}

if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['userword'];
$MM_fldUserAuthorization = "userlevel";

$MM_redirectLoginFailed = "loginfail.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_ConDB, $ConDB);

$LoginRS__query=sprintf("SELECT username, userword, userlevel FROM tbsecurity WHERE username='%s' AND userword='%s'",
get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));

$LoginRS = mysql_query($LoginRS__query, $ConDB) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {

$loginStrGroup = mysql_result($LoginRS,0,'userlevel');

//declare two session variables and assign them
$GLOBALS['MM_Username'] = $loginUsername;
$GLOBALS['MM_UserGroup'] = $loginStrGroup;

//register the session variables
session_register("MM_Username";
session_register("MM_UserGroup";

if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}

//this block does the redirect --------
if ($_SESSION['MM_UserGroup'] == 'high')
{
$MM_redirectLoginSuccess = 'high.php';
}
else
{
if ($_SESSION['MM_UserGroup'] == 'low')
{
$MM_redirectLoginSuccess = 'low.php';
}
else
{
$MM_redirectLogin = $MM_redirectLoginFailed ;
}
}
//end of redirect code------------

header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
//end of php

Reply to this topic