NerdConcepts Posted March 21, 2007 Share Posted March 21, 2007 Ok, this is what happens. When a user logs in, it assigns them a user_type from the database. Well if the person isn't logged in it gives them the default theme. There are a total of 4 different themes that can be used. Well here is the code that I am using. if (isset($_SESSION['user_type']) == '1') { $themed = 'theme/basic'; } elseif (isset($_SESSION['user_type']) == '2') { $themed = 'theme/platinum/'; } elseif (isset($_SESSION['user_type']) == '3') { $themed = 'theme/family/'; } else { // Not Logged in $themed = 'theme/default/'; } I can echo $_Session['user_type'] and I get '2' (when I am logged in as a #2 member. Well then how come when I echo $themed is comes up as 'theme/default/' when it should be 'theme/platinum/' ... ? I haven't messed with the theme stuff in a long time and thought I had it working right but I guess not. It doesn't seem to work so I guess I didn't get it working right and still can't figure it out. Link to comment https://forums.phpfreaks.com/topic/43598-theme-selection-problem/ Share on other sites More sharing options...
Iceman512 Posted March 21, 2007 Share Posted March 21, 2007 Hi there, You may want to try the following: <?php // First, we check if the session exists: if (isset($_SESSION['user_type'])) { // If it does, we'll set which theme accompanies it if (($_SESSION['user_type']) == '1') { $themed = 'theme/basic'; } elseif (($_SESSION['user_type']) == '2') { $themed = 'theme/platinum/'; } elseif (($_SESSION['user_type']) == '3') { $themed = 'theme/family/'; } // Else, if the session doesn't exist, they must not be logged in: } else { $themed = 'theme/default/'; } ?> I hope that works - I haven't tested it yet! Regards, Iceman Link to comment https://forums.phpfreaks.com/topic/43598-theme-selection-problem/#findComment-211978 Share on other sites More sharing options...
per1os Posted March 21, 2007 Share Posted March 21, 2007 If that does not work, remove the single quotes from the numbers. IE '1' should be 1, numbers do not need quotes around them. Link to comment https://forums.phpfreaks.com/topic/43598-theme-selection-problem/#findComment-212012 Share on other sites More sharing options...
NerdConcepts Posted March 21, 2007 Author Share Posted March 21, 2007 Still does the same thing. Where I am using this code is called to on every page so that every page has a theme right...well my other option was to change the 1,2,3 to 'Basic' 'Platinum' and 'Family'. So I changed the database and the coding and it still does the samething. When I echo the user_type it does show up as being 'platinum'. Yet when you echo $themed it shows up as 'theme/default/' and not 'theme/platinum/' like it should. This is the only code dealing with giving $themed a value on the whole site, so I don't know whats going on. if (isset($_SESSION['user_type'])) { if ($_SESSION['user_type'] == 'basic') { $themed = 'theme/basic'; } elseif ($_SESSION['user_type'] == 'platinum') { $themed = 'theme/platinum/'; } elseif ($_SESSION['user_type'] == 'family') { $themed = 'theme/family/'; } else { $themed = 'theme/default'; } } else { $themed = 'theme/default/'; } Link to comment https://forums.phpfreaks.com/topic/43598-theme-selection-problem/#findComment-212087 Share on other sites More sharing options...
per1os Posted March 21, 2007 Share Posted March 21, 2007 if (isset($_SESSION['user_type'])) { if (strtolower($_SESSION['user_type']) == 'basic') { $themed = 'theme/basic'; } elseif (strtolower($_SESSION['user_type']) == 'platinum') { $themed = 'theme/platinum/'; } elseif (strtolower($_SESSION['user_type']) == 'family') { $themed = 'theme/family/'; } else { $themed = 'theme/default'; } } else { $themed = 'theme/default/'; } Try converting the session values strtolower and see if it works. Remember that PHP is case SenSiTiVe Link to comment https://forums.phpfreaks.com/topic/43598-theme-selection-problem/#findComment-212097 Share on other sites More sharing options...
Iceman512 Posted March 22, 2007 Share Posted March 22, 2007 Hello again, I seem to remember having this exact same problem when trying to declare a variable conditionally... unfortunately, my memory is so poor that I can't remember how I solved the problem!! Having said that, I think the following may work: <?php $themeSet=1; if (isset($_SESSION['user_type'])) { if (strtolower($_SESSION['user_type']) == 'basic') { $themeSet+1; // Sets $themeSet to 2 } elseif (strtolower($_SESSION['user_type']) == 'platinum') { $themeSet+2; // Sets $themeSet to 3 } elseif (strtolower($_SESSION['user_type']) == 'family') { $themeSet+3; // Sets $themeSet to 4 } else { $themeSet+4; // Sets $themeSet to 5 } } else { $themeSet+5; // Sets $themeSet to 6 } // Select the theme that fits our user if ($themeSet==2){ echo '<link rel="stylesheet" type="text/css" href="/path_to_themes/theme/basic/" />'; } elseif ($themeSet==3){ echo '<link rel="stylesheet" type="text/css" href="/path_to_themes/theme/platinum/" />'; } elseif ($themeSet==4){ echo '<link rel="stylesheet" type="text/css" href="/path_to_themes/theme/family/" />'; } elseif ($themeSet==5){ echo '<link rel="stylesheet" type="text/css" href="/path_to_themes/theme/default/" />'; } elseif ($themeSet==6){ echo '<link rel="stylesheet" type="text/css" href="/path_to_themes/theme/default/" />'; } ?> I know it's a work-around and it does vastly bloat the code, but it may help you if only for testing purposes. Just drop this into the head of every page below the <title> tag. Let us know how it goes... Regards, Iceman Link to comment https://forums.phpfreaks.com/topic/43598-theme-selection-problem/#findComment-212634 Share on other sites More sharing options...
Iceman512 Posted March 23, 2007 Share Posted March 23, 2007 Hello again, I just had another thought... I haven't tested this yet, but try declaring your variable before setting it conditionally, like this: <?php $themed = ''; // This line creates and sets the variable if (isset($_SESSION['user_type']) == '1') { $themed = 'theme/basic'; } elseif (isset($_SESSION['user_type']) == '2') { $themed = 'theme/platinum/'; } elseif (isset($_SESSION['user_type']) == '3') { $themed = 'theme/family/'; } else { // Not Logged in $themed = 'theme/default/'; } Give that a try and let's see if it works, Best Regards, Iceman Link to comment https://forums.phpfreaks.com/topic/43598-theme-selection-problem/#findComment-213513 Share on other sites More sharing options...
per1os Posted March 23, 2007 Share Posted March 23, 2007 Along with icemans suggestion maybe do this too =) <?php $themed = ''; // This line creates and sets the variable $user_type = $_SESSION['user_type']; if (isset($user_type) == '1') { $themed = 'theme/basic'; } elseif (isset($user_type) == '2') { $themed = 'theme/platinum/'; } elseif (isset($user_type) == '3') { $themed = 'theme/family/'; } else { // Not Logged in $themed = 'theme/default/'; } Link to comment https://forums.phpfreaks.com/topic/43598-theme-selection-problem/#findComment-213516 Share on other sites More sharing options...
Iceman512 Posted March 23, 2007 Share Posted March 23, 2007 Good thinking Frost! Let's take it a bit further and first check whether the session is set, that way we'll be able to confirm that the session actually exists: <?php $themed = ''; // This line creates and sets the variable $user_type = $_SESSION['user_type']; if (isset($user_type)){ if ($user_type == '1') { $themed = 'theme/basic'; } elseif ($user_type == '2') { $themed = 'theme/platinum/'; } elseif ($user_type == '3') { $themed = 'theme/family/'; } } elseif (!isset($user_type)){ $themed = 'theme/default/'; echo 'The session "'.$user_type.'" does not exist'; } else { $themed = 'theme/default/'; echo 'An unkown error has occurred.'; } ?> Regards, Iceman Link to comment https://forums.phpfreaks.com/topic/43598-theme-selection-problem/#findComment-213522 Share on other sites More sharing options...
per1os Posted March 23, 2007 Share Posted March 23, 2007 Ohhhh now your really on a row iceman! =P Link to comment https://forums.phpfreaks.com/topic/43598-theme-selection-problem/#findComment-213534 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.