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.

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

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 )

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


?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.