Jump to content

[SOLVED] PHP Login with access level


Decrepidos

Recommended Posts

Hi

If this has been answered previously please direct me to the post as I could not see it in the forum.

I am trying, yes I am a novice, to update the standard DW login script with access lvl below so that depending on the access lvl set the redirect opens a different page. If the access lvl is admin then admin.com.au opens if its user user.com.au opens. that kinda thing.

I think I need to use and if else or a switch statement, trouble is I need a starting point and I have no idea where to start.

Thanks for any help and advice

Cheers
Decrep
[code]
<?php require_once('Connections/DB_MyDatabase'); ?>
<?php
// *** Validate request to login to this site.
session_start();

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($accesscheck)) {
  $GLOBALS['PrevUrl'] = $accesscheck;
  session_register('PrevUrl');
}

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "access";
  $MM_redirectLoginSuccess = "page1.php";
  $MM_redirectLoginFailed = "failed.php";
  $MM_redirecttoReferrer = true;
  mysql_select_db($database_DB_AIOP, $DB_AIOP);
 
  $LoginRS__query=sprintf("SELECT userName, password, access FROM recordset WHERE userName='%s' AND password='%s'",
  get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
 
  $LoginRS = mysql_query($LoginRS__query, $DB_AIOP) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
   
    $loginStrGroup  = mysql_result($LoginRS,0,'access');
   
    //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']) && true) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/31465-solved-php-login-with-access-level/
Share on other sites

After this line....

[code=php:0]
header("Location: " . $MM_redirectLoginSuccess );
[/code]

you might try something like (as an example)...

[code=php:0]
switch ($loginStrGroup) {
  case 'user':
    header("Location: user.php");
    break;
  case 'admin':
    header("Location admin.php");
    break;
  default:
    header("Location: " . $MM_redirectLoginSuccess );
}
[/code]

IMO You really ought to learn php [b]before[/b] letting dreamweaver write code for you. Besides the fact that it writes terribbly inificient and hard to read / maintain code, it really doesn't help the learning process at all.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.