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,807
    Likes Received:
    4,534
    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,807
    Likes Received:
    4,534
    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