ev5unleash Posted May 24, 2009 Share Posted May 24, 2009 Hey Everyone, I'm having trouble with PHP include once again. I'm using this code <?php include('indextop.html'); if( !isset($_GET['id']) ) { $xid = 'default'; } else { $xid = strtolower($_GET['id']); } switch($xid) { case 'about': include('about.html'); break; case 'default': include('indexhome.html'); break; case 'jailbreak': include('jailbreak.html'); break; case 'jailbreak1': include('jailbreak1.html'); break; case 'jailbreak2': include('jailbreak2.html'); break; case 'jailbreak3': include('jailbreak3.html'); break; case 'jailbreak4': include('jailbreak4.html'); break; case 'download': include('download.php'); break; } include('indexbot.html'); ?> My problem is that when you enter something that is not a case like page.php?id=sjhfksjdhflksajdhf then it will be a blank page. I would like to have the page default to the indexhome.html page instead of leaving it blank. I'm also having a problem where I cannot include multiple times, like index.php includes to download.php that has another set of pages, if I do this, I would be presented with a blank middle page. Could anyone help me? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/159481-solved-php-include-blank-when-nothing-entered/ Share on other sites More sharing options...
ev5unleash Posted May 24, 2009 Author Share Posted May 24, 2009 Could I get this moved to 'PHP Help' Please? I've accidentally posted in the wrong location. Quote Link to comment https://forums.phpfreaks.com/topic/159481-solved-php-include-blank-when-nothing-entered/#findComment-841254 Share on other sites More sharing options...
PFMaBiSmAd Posted May 24, 2009 Share Posted May 24, 2009 The switch/case structure has a default option. You can read about it in the documentation - switch Quote Link to comment https://forums.phpfreaks.com/topic/159481-solved-php-include-blank-when-nothing-entered/#findComment-841255 Share on other sites More sharing options...
ev5unleash Posted May 24, 2009 Author Share Posted May 24, 2009 I know, but is there someone who could put it in for me? Cause I'm new to PHP and I need this site up very soon. Quote Link to comment https://forums.phpfreaks.com/topic/159481-solved-php-include-blank-when-nothing-entered/#findComment-841311 Share on other sites More sharing options...
wildteen88 Posted May 24, 2009 Share Posted May 24, 2009 Move these lines case 'default': include('indexhome.html'); break; To the bottom of your switch. Now add default: after case 'default': Quote Link to comment https://forums.phpfreaks.com/topic/159481-solved-php-include-blank-when-nothing-entered/#findComment-841314 Share on other sites More sharing options...
Axeia Posted May 24, 2009 Share Posted May 24, 2009 This might be a bit easier to maintain. switch($xid) { case 'about': case 'jailbreak': case 'jailbreak1': case 'jailbreak2': case 'jailbreak3': case 'jailbreak4': $xid.'.html'; break; case 'download': include('download.php'); break; case 'default': case default: include('indexhome.html'); } Quote Link to comment https://forums.phpfreaks.com/topic/159481-solved-php-include-blank-when-nothing-entered/#findComment-841320 Share on other sites More sharing options...
ev5unleash Posted May 24, 2009 Author Share Posted May 24, 2009 Is that easier to use? Cause sometimes I use it for downloads, php pages and other type of documents Quote Link to comment https://forums.phpfreaks.com/topic/159481-solved-php-include-blank-when-nothing-entered/#findComment-841323 Share on other sites More sharing options...
ev5unleash Posted May 24, 2009 Author Share Posted May 24, 2009 Okay so you mean that I should have the default like this? default case 'default': include('downerror.html'); break; at the bottom of the other cases? Quote Link to comment https://forums.phpfreaks.com/topic/159481-solved-php-include-blank-when-nothing-entered/#findComment-841324 Share on other sites More sharing options...
Axeia Posted May 24, 2009 Share Posted May 24, 2009 See my example, it's your case and even the default is in there, I messed up the include though, it just created a string instead of including anything, fixed version below: switch($xid) { case 'about': case 'jailbreak': case 'jailbreak1': case 'jailbreak2': case 'jailbreak3': case 'jailbreak4': include( $xid.'.html' ); break; case 'download': include('download.php'); break; case 'default': case default: include('indexhome.html'); } For all cases above the first break it will use the filename itself and add .'html' behind it. In my opinion that's easier to maintain since if you want to add say a new page 'sample' you simply add case 'sample': and you're done. A lot shorter than a whole new case including a break which would be 3 lines (opposed to 1 ) Quote Link to comment https://forums.phpfreaks.com/topic/159481-solved-php-include-blank-when-nothing-entered/#findComment-841333 Share on other sites More sharing options...
ev5unleash Posted May 24, 2009 Author Share Posted May 24, 2009 But you don't see that I don't always use just html for one document, I use other types and I would like it so I could specific the filetype with it's name but having .html added to all of them Quote Link to comment https://forums.phpfreaks.com/topic/159481-solved-php-include-blank-when-nothing-entered/#findComment-841334 Share on other sites More sharing options...
Axeia Posted May 24, 2009 Share Posted May 24, 2009 The example would add .html to about, jailbreak, jailbreak1-4 Unless you got an about.php, jailbreak.php or jailbreak1/2/3/4.php there shouldn't be a problem, and if there is there would be a problem with the old code as well. Quote Link to comment https://forums.phpfreaks.com/topic/159481-solved-php-include-blank-when-nothing-entered/#findComment-841360 Share on other sites More sharing options...
ev5unleash Posted May 24, 2009 Author Share Posted May 24, 2009 So I can remove your .html from the code if I use multiple file types? Quote Link to comment https://forums.phpfreaks.com/topic/159481-solved-php-include-blank-when-nothing-entered/#findComment-841368 Share on other sites More sharing options...
ev5unleash Posted May 24, 2009 Author Share Posted May 24, 2009 Let me show you what my real problem is with this include. I have this page http://ev5unleash.dnsalias.org:1212/websites/schoolsites/scrogfinal/index.php and when I do http://ev5unleash.dnsalias.org:1212/websites/schoolsites/scrogfinal/index.php?id=download&os=windows the middle page disappears and I don't get the page I wanted. index.php <?php include('indextop.html'); if( !isset($_GET['id']) ) { $xid = 'default'; } else { $xid = strtolower($_GET['id']); } switch($xid) { case 'about': include('about.html'); break; case 'jailbreak': include('jailbreak.html'); break; case 'jailbreak1': include('jailbreak1.html'); break; case 'jailbreak2': include('jailbreak2.html'); break; case 'jailbreak3': include('jailbreak3.html'); break; case 'jailbreak4': include('jailbreak4.html'); break; case 'download': include('download.php'); break; case 'about': include('about.html')l break; case 'default': include('indexhome.html'); break; } include('indexbot.html'); ?> download.php <?php if( !isset($_GET['os']) ) { $xid = 'default'; } else { $xid = strtolower($_GET['os']); } switch($xid) { case 'mac': include('download/mac.html'); break; case 'windows': include('download/windows.html'); break; default case 'default'; include('downerror.html'); break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/159481-solved-php-include-blank-when-nothing-entered/#findComment-841372 Share on other sites More sharing options...
wildteen88 Posted May 24, 2009 Share Posted May 24, 2009 This code in download.php: default case 'default'; include('downerror.html'); break; needs to be case 'default': default: include('downerror.html'); break; Also your links when you go to the jailbreal page should be index.php?id=download&os=windows not index.php?id=download?os=windows Quote Link to comment https://forums.phpfreaks.com/topic/159481-solved-php-include-blank-when-nothing-entered/#findComment-841373 Share on other sites More sharing options...
ev5unleash Posted May 24, 2009 Author Share Posted May 24, 2009 Ahh, Thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/159481-solved-php-include-blank-when-nothing-entered/#findComment-841375 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.