Jump to content

[SOLVED] PHP Include, blank when nothing entered


ev5unleash

Recommended Posts

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.

Link to comment
Share on other sites

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');
}

Link to comment
Share on other sites

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 )

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;
}


?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.