Include a file based on the url of the page

Discussion in 'PHP' started by pablo, Jan 18, 2007.

  1. #1
    Is there an easy way to to this ?
    I want to write a general template that will include one of these parts depending on the file that is called
    if file1.php include
    <?php
    chdir("../includes");
    include 'include1.inc';  
    ?> 
    PHP:
    if file2.php include
    
    <?php
    chdir("../includes");
    include 'include2.inc';  
    ?> 
    PHP:
    any hints on what I should look in to ?

    Thanks for your help !

    p
     
    pablo, Jan 18, 2007 IP
  2. disgust

    disgust Guest

    Messages:
    2,417
    Likes Received:
    133
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $_SERVER['REQUEST_URI'] will give you /file1.php, etc, as a string. you can manipulate it from there to do what you want.
     
    disgust, Jan 18, 2007 IP
    pablo likes this.
  3. pablo

    pablo Well-Known Member

    Messages:
    301
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    110
    #3
    thanks .... green given!
     
    pablo, Jan 18, 2007 IP
  4. pablo

    pablo Well-Known Member

    Messages:
    301
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    110
    #4
    hmmm.... maybe I need more info incase file1 and file2 are not in the same directory. agh!

    EDIT : it seems it will give a list of the directories and path aswell. Thanks !
     
    pablo, Jan 18, 2007 IP
  5. pablo

    pablo Well-Known Member

    Messages:
    301
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    110
    #5
    pablo, Jan 18, 2007 IP
  6. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #6
    Use ModRewrite to convert the folder path to a querystring variable, then use your $_GET['var'] to define which include to use
     
    ccoonen, Jan 19, 2007 IP