|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Switch Case code to redirect from a link based on session variable
I'm writing a web app (php/mysql) for a college with 29 departments. I have a login page which checks username and password against the DB and if it finds the user also pulls down an access_level variable:
$loginStrGroup = mysql_result($LoginRS,0,'access_level'); //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"); Then, based upon the access_level stored in $loginStrGroup, I redirect the logged in user to one of five pages by means of a switch case expression: switch ($loginStrGroup) { case 1: header("Location: switchboard01.php"); break; case 2: header("Location: switchboard02.php"); break; case 3: header("Location: switchboard03.php"); break; case 4: header("Location: switchboard04.php"); break; case 5: header("Location: switchboard05.php"); } All that works perfectly. Here's my problem -- some pages in the app need to be shared by users with different access levels. On one such page I have a link back to the switchboard, but it's a hard-coded link and returns all users back to just one switchboard. How can I reference the session variable $loginStrGroup in such a way that any user who clicks the link will be sent back to his/her proper switchboard? I've tried a few variations in code but can't get it to work. Thanks. Jerry |
|
#2
|
|||
|
|||
|
Would something like this work?
PHP Code:
Though it looks like it would be just as easy to set up your links to the switchboard like this, too: PHP Code:
as long as the $loginStrGroup is an integar that matches up with the proper switchboard file. |
|
#3
|
|||
|
|||
|
Here's how I did it
Madpawn,
Here's how I did it: Declared additional Globals on the login page: //declare three session variables and assign them $GLOBALS['MM_Username'] = $loginUsername; $GLOBALS['MM_UserGroup'] = $loginStrGroup; $GLOBALS['MM_UserHomePage'] = 'switchboard0'.$loginStrGroup.'.php'; //register the session variables session_register("MM_Username"); session_register("MM_UserGroup"); session_register("MM__UserHomePage"); Then formatted the link on the shared page this way: Back to <?php echo "<a href='switchboard0".$GLOBALS['MM_UserGroup'].".php'> Switchboard </a>"; ?> It works very well. Your code would have worked too, except I could not get the $loginStrGroup variable to pass consistently. Thanks for the reply. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Switch Case code to redirect from a link based on session variable |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|