Forums
This topic is locked
Dynamic Redirect at Login
Posted 15 Aug 2007 17:51:49
1
has voted
15 Aug 2007 17:51:49 Kurt Buesching posted:
Hi - I need to redirect the user after login to one of 5 different pages based on the group (UserInterest) the user may belong to. The following code always takes me to index.php if successful or member_login_fail.php if it isn't. How can I redirect to the appropriate page based on this session variable? I've been able to find ASP versions of this issue but not in PHP - any help will be greatly appreciated.Here is my login script...
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "UserInterest";
$MM_redirectLoginSuccess = "index.php";
$MM_redirectLoginFailed = "member_login_fail.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_tencore, $tencore);
switch($MM_fldUserAuthorization) {
case 'homeowner':
$MM_redirectLoginSuccess = "homeowners.php";
break;
case 'investor':
$MM_redirectLoginSuccess = "investors.php";
break;
case 'non-Profit developer':
$MM_redirectLoginSuccess = "nonprofit.php";
break;
case 'developer':
$MM_redirectLoginSuccess = "developers.php";
return $MM_redirectLoginSuccess;
}
$LoginRS__query=sprintf("SELECT UserEmail, UserPassword, UserInterest FROM Users WHERE UserEmail=%s AND UserPassword=%s",
GetSQLValueString($loginUsername, "text"
$LoginRS = mysql_query($LoginRS__query, $tencore) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = mysql_result($LoginRS,0,'UserInterest');
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
Thanks in advance - Kurtster