exclude <? include("xxxxx.php"); ?> on certain pages

Discussion in 'PHP' started by BaDaBinG, Feb 7, 2007.

  1. #1
    Hi all.

    I did search for this before I made a thread, problem is I don't really know what to search for

    My problem is:

    I have a lot of <? include("xxxxx.php"); ?> on my index page. Is it possible to exclude some includes on certain pages. For example say you go to www.mywebsite.com/index.php?site=forum and don't want <? include("xxxxx.php"); ?> to show on that page.

    http://www.ninthgaming.com/ this is the site im working on and at the moment.


    I will be very greatful for any help on this.
     
    BaDaBinG, Feb 7, 2007 IP
  2. eugen

    eugen Active Member

    Messages:
    154
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Of course you can.

    For example:
    
    switch( $_GET['site'] ) {
        default:
           include( "xxxxx.php" );   // any case excluding forum
           break;
    
        case 'forum':
           break;
    }
    
    Code (markup):
    You can add more cases if u want.

    I hope this helps u.
     
    eugen, Feb 7, 2007 IP
  3. jumpenjuhosaphat

    jumpenjuhosaphat Peon

    Messages:
    229
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I'm still new, but I'll give it my best shot.

    
    if($_GET['site']!="forum") include('suchnsuch.file');
    
    Code (markup):
     
    jumpenjuhosaphat, Feb 7, 2007 IP
  4. BaDaBinG

    BaDaBinG Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thx for the fast reply, ill try it out and see if can get it to work. Im a total noob at php.
     
    BaDaBinG, Feb 7, 2007 IP
  5. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #5
    First of all make an array of pages where you don't want to include file "xxxxx.php"

    $excludePages = array();
    $excludePages[] = "forums.php";
    $excludePages[] = "contact.php";
    PHP:
    Then add following code where you are including "xxxxx.php"

    $currentPage = str_replace("/", "", $_SERVER['PHP_SELF'];
    if(!in_array($currentPage, $excludePages))
         include("xxxxxx.php");
    PHP:
    Hope this will help.
     
    designcode, Feb 7, 2007 IP