tags:

views:

39

answers:

2

I have a login form through which one of three types of users gets into the website (PHP-based). Upon login the index page should load with the navigation bar based on user type. Right now the login page loads the index without checking for user type. How to achieve this?

I'm not using any PHP framework.

A: 

either 1. A simple switch statement userType switch(userType) { case 1:{ //do stuff break();} etc

Or you could have named includes load particular include files based on role variable

e.g include_once({$userType}.php

Shaun Hare
Hey, thanks for the quick answer. I need to load the navigation in a background way - i.e., the difference should not be visible in the URI.
ekalaivan
just for reference either of theset would not change url
Shaun Hare
+1  A: 

During the login process, store the user's usertype into the session:

session_start();

// ...

// if the user's login was successful:
$_SESSION["user_type"] = 1; // or similar

then you can check on each subsequent page load what type the user is and include the relevant navigation bar:

session_start();

switch ($_SESSION["user_type"])
{
  case 1:
    // nav type 1
    break;

  default:
    // default navigation bar
    break;
}

Don't forget to call session_start() on each page you need this information, although I'm presuming you're doing that anyway since you have logged-in and non-logged-in users...!

richsage
Fantastic. I was sitting on this for a couple of days now. Thanks for your help.
ekalaivan
No problem! :-)
richsage