n00bert Posted July 6, 2009 Share Posted July 6, 2009 ok I have been using this switch function with no problems on my old server. Now that I have switched to a new server it no longer works. So i'm almost positive it's a setting in the php.ini or something. It will display the default: just fine but it will not display any of the cases.. Quote Link to comment Share on other sites More sharing options...
Andy-H Posted July 6, 2009 Share Posted July 6, 2009 Nice code... Quote Link to comment Share on other sites More sharing options...
seventheyejosh Posted July 6, 2009 Share Posted July 6, 2009 that is some of the nicest code i've ever seen! the file size must be practically non-existent! Quote Link to comment Share on other sites More sharing options...
n00bert Posted July 6, 2009 Author Share Posted July 6, 2009 ummm I just figured you knew what a switch function was.. my apologies. <?php switch($page){ default: include 'quotes.php'; break; case quotes: include 'quotes.php'; break; case msgs: include 'messages.php'; break; } ?> Quote Link to comment Share on other sites More sharing options...
seventheyejosh Posted July 6, 2009 Share Posted July 6, 2009 have you tried echoing $page to make sure its hitting a case? Quote Link to comment Share on other sites More sharing options...
Andy-H Posted July 6, 2009 Share Posted July 6, 2009 <?php switch($page) { /* case "quotes": include 'quotes.php'; break; */ case "msgs": include 'messages.php'; break; default: include 'quotes.php'; } ?> Default clause should be last and doesnt require a break; after it. Assuming your cases arent testing for constants you need to quote the strings, if you were using defined constants, remove the quotes I added. //* EDIT No point in having a case that gives the same result as your default clause... Quote Link to comment Share on other sites More sharing options...
n00bert Posted July 6, 2009 Author Share Posted July 6, 2009 ok seven you were correct. I tried to echo $page and I got nothing. So I enabled register_globals in my php.ini and now everything works. Andy thanks you as well for the advice. BTW.. should I not enable register globals? is there a better way around this? Quote Link to comment Share on other sites More sharing options...
seventheyejosh Posted July 6, 2009 Share Posted July 6, 2009 i believe that one of the first rules of php is never ever ever register globals. what part is above your code? how are u getting page? $_REQUEST? post? is it coming via a form? or read from the url? Quote Link to comment Share on other sites More sharing options...
Zane Posted July 6, 2009 Share Posted July 6, 2009 ok seven you were correct. I tried to echo $page and I got nothing. So I enabled register_globals in my php.ini and now everything works. Andy thanks you as well for the advice. BTW.. should I not enable register globals? is there a better way around this? Yes, register_globals is BAD. instead of $page use $_GET['page'] or $_POST['page']....depending on which one you're using Quote Link to comment Share on other sites More sharing options...
n00bert Posted July 6, 2009 Author Share Posted July 6, 2009 Ok, I've disabled register_globals again and now i'm using $_GET['page'] instead of page.. everything works great.. Thanks for all the help folks! Quote Link to comment Share on other sites More sharing options...
seventheyejosh Posted July 6, 2009 Share Posted July 6, 2009 Not a problem, be sure to mark as solved! Quote Link to comment 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.