Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2002
    Location
    http://www.hostriot.com
    Posts
    135

    Simple PHP question...

    What would be the code for a index.php to have content in the middle of the page(text, images, etc...), but when a link is click(lets say services) it runs index.php?page=services, and it replaces the content that was in the middle. I know how to do this when your already on a ?page=BLAH, but I do not know how to make it so the default content on the index.php gets replaced...

    Anyone know the answer?

  2. #2
    Join Date
    Sep 2002
    Posts
    96
    This should work:

    Code:
    <?php 
    if(is_file("$page.php")) 
    {
    include("$page.php");
    }
    else
    {
    include("default.php");
    }
    ?>
    Last edited by Xandra; 09-22-2002 at 12:11 PM.

  3. #3
    Join Date
    Nov 2000
    Posts
    3,046
    In a recent post we went through this too... But MAKE SURE you do error checking so that an important file isn't included:

    Code:
    if (preg_match("/\W/")) {
      include("default.php");
    }
    This way if the user changes $page and uses ../../someuser/sql.conf it'll only include the default page (\W matches any character that is not alphanumeric or an underscore).
    A well-reasoned assumption is very close to fact.
    - Adorno

  4. #4
    Join Date
    Apr 2002
    Location
    Philadelphia
    Posts
    2,278
    PHP Code:
    <HTML>
    <TITLE>Home</TITLE>
    <HEAD>
    </HEAD>
    <BODY>

    <?php 
                            
       
    if(empty($page)) {
                    
                include 
    "index2.html";
                            
       } else {
                            
                include 
    "$page.html";
                            
     }

    ?>

    </BODY>
    </HTML>
    Last edited by phpcoder; 09-22-2002 at 03:39 PM.

  5. #5
    Join Date
    Aug 2002
    Location
    Toronto, Canada
    Posts
    286
    Yes, I used these methods on my web page.... check it out....
    www.prolinker.com - free automatic linking to your website

  6. #6
    Join Date
    Nov 2001
    Posts
    857
    If I might give a suggestion.

    when you make your template page that will insert the content page into the middle put it in a non web directory..

    Then put each page in its own folder.

    I.E. The only page in http://www.mydomain.com/ is your home page. Then put your plans page in http://www.mydomain.com/plans
    etc etc etc.

    This is done by creating a index.php file in each directory. That index.php file sets the variable page and any other variables you may want to pre define for that particular page, IE dynamic menues etc. After it sets the variables it does a require() to your template page in the non web directory.

    This does a few more things for you.
    (1) It gives you more control over what you can do. Like with the dynamic menus in the template.
    (2) It makes the URLs easy for users to cut, paste and share with their friends which is always a good thing.
    (3) The users never see anything like ?page=whatever etc.

    Regards,
    Michael
    <?
    header("Location: http://www.hostevolve.com/");
    ?>

  7. #7
    Join Date
    May 2002
    Location
    UK
    Posts
    2,997
    Please, please, please call page as $_GET['page'] though as opposed to $page.

    You may find that the latter method doesn't work on all servers as it's been disabled.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •