PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 9th, 2005, 07:14 AM
massiej massiej is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 3 massiej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 34 sec
Reputation Power: 0
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



Reply With Quote
  #2  
Old February 9th, 2005, 12:15 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 4
Would something like this work?

PHP Code:
switch ($loginStrGroup) { 
  case 
1
 
$switchboard_link 'switchboard01.php'
  break; 
  case 
2
 
$switchboard_link 'switchboard02.php'
  break; 
  case 
3
 
$switchboard_link 'switchboard03.php'
  break;
  case 
4
 
$switchboard_link 'switchboard04.php'
  break;
  case 
5
 
$switchboard_link 'switchboard05.php'
  }
 
 echo 
'<a href="' $switchboard_link '">' $switchboard_link '</a>'


Though it looks like it would be just as easy to set up your links to the switchboard like this, too:

PHP Code:
echo '<a href="switchboard0' $loginStrGroup '">Your Switchboard</a>'


as long as the $loginStrGroup is an integar that matches up with the proper switchboard file.

Reply With Quote
  #3  
Old February 9th, 2005, 03:00 PM
massiej massiej is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 3 massiej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 34 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Switch Case code to redirect from a link based on session variable


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT