Skip to main content
Participant
April 23, 2009
Answered

User Authentication

  • April 23, 2009
  • 1 reply
  • 506 views

Hi

I am using Dreamweaver CS4 and have created many login pages using the server behaviour without a problem. What I now need to do is create one login page and depending on 8 different access levels point the user to one of 8 different pages. The access levels are all setup but is there any way to direct a user to a specific page depending on their access level? I can do it using the previous url method but wondered if there is any way to echo out the access level variable (the page name eg levelone.php) in the success url within the login form?

Any help appreciated.

Thanks Nikki

This topic has been closed for replies.
Correct answer David_Powers

This involves editing the Log In User server behavior code generated by Dreamweaver, so it will no longer be editable through the server behavior dialog box. However, making the changes are quite simple.

The final section of the code created by Dreamweaver looks like this:

    //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 );
  }
}

You need to use $loginStrGroup to determine the name of the page that you are redirecting people to. Do this with a switch() statement.

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

     // set the destination page depending on access level

     switch($loginStrGroup) {

      case 'accesLevel1':

        $MM_redirectLoginSuccess = 'level1.php';

        break;

      case 'accessLevel2':

        $MM_redirectLoginSuccess = 'level2.php';

        break;

      // create similar case statements for the remaining six levels

    }

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];     
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}

1 reply

David_Powers
David_PowersCorrect answer
Inspiring
April 23, 2009

This involves editing the Log In User server behavior code generated by Dreamweaver, so it will no longer be editable through the server behavior dialog box. However, making the changes are quite simple.

The final section of the code created by Dreamweaver looks like this:

    //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 );
  }
}

You need to use $loginStrGroup to determine the name of the page that you are redirecting people to. Do this with a switch() statement.

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

     // set the destination page depending on access level

     switch($loginStrGroup) {

      case 'accesLevel1':

        $MM_redirectLoginSuccess = 'level1.php';

        break;

      case 'accessLevel2':

        $MM_redirectLoginSuccess = 'level2.php';

        break;

      // create similar case statements for the remaining six levels

    }

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];     
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}

Participant
April 23, 2009

Thanks David.

I thought there must be a simple answer to this.

Just tested it and it works a treat.

Thanks again

Nikki