NerdConcepts Posted March 1, 2007 Share Posted March 1, 2007 Ok, here is what I am trying to do. When someone logins in it gives them a "user_id" and "user_type" which is based off of a num (0-3) stored in the database...I have that working just fine. Since when $_Session['user_type'] is echoed it shows up the right number. Well, I am trying to write a theme selector based off of the users "user_type" . I see if the ['user_type'] is set, if it is then it moves that number (0-3) to a variable called $usertheme. If it is not set (else) then it makes the default value of $usertheme as '0'. Then at the end it asks if the $usertheme value is 0, 1, 2, 3 and defines the proper $themed value. $themed is then referenced in the main theme files to change the directory to which is looks for images/files etc to show the theme. You may understand this more...here is my code (excluding me calling to $themed). When I log in and echo $_SESSION['user_type'] I get the right value. Yet when I echo $usertheme or $themed is comes up with '0'...always...not matter if I am logged in or not. Also, when I place any "else" or "elseif" commands in the 2nd part it comes up with an error. Saying the else/elseif is unexpected. I've been playing with this for quite sometime now and cannot figure it out... -------------------------------------- if (isset($_SESSION['user_id'])) { // Logged in Already...get User Type.... $usertheme = $_SESSION['user_type']; } else { // No Match $usertheme = '0'; } // Make $usertheme $themed and define it if ($usertheme == '1'); { // Not Logged or Free $themed = 'theme/platinum/'; } -------------------------------------- Quote Link to comment https://forums.phpfreaks.com/topic/40633-isset-isnt-working-like-i-thought-it-would/ Share on other sites More sharing options...
MadTechie Posted March 1, 2007 Share Posted March 1, 2007 just a quick note if ($usertheme == '1'); can you show your echo points! Quote Link to comment https://forums.phpfreaks.com/topic/40633-isset-isnt-working-like-i-thought-it-would/#findComment-196520 Share on other sites More sharing options...
NerdConcepts Posted March 1, 2007 Author Share Posted March 1, 2007 example of the code and what it prints echo $themed; returns "themes/platinum/" echo $usertheme; returns "0" echo $_SESSION['user_type']; returns "2" when $usertheme should be echoed as "2" Quote Link to comment https://forums.phpfreaks.com/topic/40633-isset-isnt-working-like-i-thought-it-would/#findComment-196534 Share on other sites More sharing options...
MadTechie Posted March 1, 2007 Share Posted March 1, 2007 first thing with isset, is that if it is null it is still set, so you may want to check if its empty also are you using the session correctly <?php session_start(); // start up your PHP session! ?> Also, when I place any "else" or "elseif" commands in the 2nd part it comes up with an error. Saying the else/elseif is unexpected. I've been playing with this for quite sometime now and cannot figure it out... Change if ($usertheme == '1'); { // Not Logged or Free $themed = 'theme/platinum/'; } to if ($usertheme == '1') { // Not Logged or Free $themed = 'theme/platinum/'; } note the ");" has been removed Quote Link to comment https://forums.phpfreaks.com/topic/40633-isset-isnt-working-like-i-thought-it-would/#findComment-196538 Share on other sites More sharing options...
NerdConcepts Posted March 1, 2007 Author Share Posted March 1, 2007 if (isset($_SESSION['user_id'])) { // Logged in Already...get user_type.... $usertheme = $_SESSION['user_type']; } else { // No Match so assign user_type $usertheme = '0'; } if ($usertheme == '1') { // Basic theme $themed = 'theme/default/'; } elseif ($usertheme == '2') { // Platinum theme $themed = 'theme/basic/'; } elseif ($usertheme == '3') { // Family theme $themed = 'theme/platinum/'; } else { // Not Logged in or Default theme $themed = 'theme/default/'; } That is the new code. Yet it always seems to have a $themed value of '0' ... When it should be '2' when I am logged in. I would think that it is in the first part of the code, yet I cannot seem to figure out what is wrong with it. Also. There is always a session when on the site. When Logged in: echo $usertheme = '0' (when it should be '2'). because echo $_SESSION['user_type'] shows as '2' like it should. BTW, the user I logged in is 'user_type' = '2', defined by the login grabbing the information out of the database. Quote Link to comment https://forums.phpfreaks.com/topic/40633-isset-isnt-working-like-i-thought-it-would/#findComment-196554 Share on other sites More sharing options...
MadTechie Posted March 1, 2007 Share Posted March 1, 2007 OK this works 1st run i uncommented the $_SESSION['user_id'] = "its_me"; $_SESSION['user_type'] = "2"; result themed - theme/basic/ usertheme - 2 commented them and ran again result themed - theme/basic/ usertheme - 2 so i would check you have session_start(); at the start <?php session_start(); //$_SESSION['user_id'] = "its_me"; //$_SESSION['user_type'] = "2"; if (isset($_SESSION['user_id'])) { // Logged in Already...get user_type.... $usertheme = $_SESSION['user_type']; } else { // No Match so assign user_type $usertheme = '0'; } if ($usertheme == '1') { // Basic theme $themed = 'theme/default/'; } elseif ($usertheme == '2') { // Platinum theme $themed = 'theme/basic/'; } elseif ($usertheme == '3') { // Family theme $themed = 'theme/platinum/'; } else { // Not Logged in or Default theme $themed = 'theme/default/'; } echo "themed - $themed<br>"; echo "usertheme - $usertheme"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/40633-isset-isnt-working-like-i-thought-it-would/#findComment-196562 Share on other sites More sharing options...
btherl Posted March 1, 2007 Share Posted March 1, 2007 Actually, null is "not set". It's an empty string that is set. The full table is here: http://sg.php.net/manual/en/types.comparisons.php Quote Link to comment https://forums.phpfreaks.com/topic/40633-isset-isnt-working-like-i-thought-it-would/#findComment-196568 Share on other sites More sharing options...
MadTechie Posted March 1, 2007 Share Posted March 1, 2007 thanx for the info.. (another print out for the wall) Quote Link to comment https://forums.phpfreaks.com/topic/40633-isset-isnt-working-like-i-thought-it-would/#findComment-196574 Share on other sites More sharing options...
NerdConcepts Posted March 1, 2007 Author Share Posted March 1, 2007 Well that is something I didn't notice at first. There is tons of code that I have for the theme, header, footer, error_handler(s), mysql connect files, etc etc. Well I was calling to that code I showed right before I called to the file header, which started the session. So I re-wrote some stuff and now it's fixed. Values are returning like normal and it all works. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/40633-isset-isnt-working-like-i-thought-it-would/#findComment-196594 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.