1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP include only if on homepage

Discussion in 'PHP' started by fadetoblack22, Oct 25, 2011.

  1. #1
    What do I need to add to this code to make it only include file.php if on the homepage?

    <?php include("file.php"); ?>

    Thank you.
     
    Solved! View solution.
    fadetoblack22, Oct 25, 2011 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #2
    I'd do an if where you look at $_SERVER['REQUEST_URI'] (I think), do a var_dump($_SERVER) to see what your options are.
     
    sarahk, Oct 25, 2011 IP
  3. fadetoblack22

    fadetoblack22 Well-Known Member

    Messages:
    2,399
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    160
    #3
    Sorry, I don't understand your answer as I don't know php.
     
    fadetoblack22, Oct 26, 2011 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #4
    Then you need to learn the basics before you go messing with your site. PHP is super easy to learn.
     
    sarahk, Oct 26, 2011 IP
  5. #5
    Assuming your home page is index.php (and you have mod_rewrite urls) you could do something like this:

    
    $base = basename( $_SERVER[ 'PHP_SELF' ] );
           
    if ( ($base == 'index.php') && (dirname($_SERVER['PHP_SELF']) === '/') ) {
        include_once "file.php";
    } 
    
    PHP:
     
    Dimmo, Oct 26, 2011 IP