Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Differen includes

    Hi,

    I have a list of links on the left.
    Next to it i want to load the page that is together with the link (with include).

    Example:

    I click on the first link then the file (include1.php) should show up in the table next to the list of links.
    Then i click on the second link and the file (include2.php) should show up in the table next to the list of links.

    I know how to include a file.
    For the first link it = <td><?php include("include1.php") ?></td>
    For the second one = <td><?php include("include2.php") ?></td>

    But how can i include different files in that same table when i click on a specific link on the left (i don't want to use frame).

    I hope anyone can help me out with this. Thank you.

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can pass a variable to the url from the link which PHP can use to determine which file to include. For instance:
    PHP Code:
    // This is your menu
    <a href="page.php?id=home">Homepage</a>
    <a href="page.php?id=products">Products</a>
    <a href="page.php?id=contact">Contact</a>

    <?php
    // now let's decide what page to include - the default is "home"
    $_GET['id'] = (isset($_GET['id']) ? $_GET['id'] : 'home');

    // next we create an array of allowed pages for security purposes only these pages will be loaded as included files
    $allowed_pages = array("home""products""contact");

    if(!
    in_array($_GET['id'], $allowed_pages)) {

        echo 
    'Sorry, the page you selected could not be found. It may have been moved or deleted.';

    } else {

        include(
    $_GET['id'] . '.php');
        
    }
    This has some added security as it will only include pages you specifically add to the $allowed_pages array.

  • #3
    New Coder
    Join Date
    Jul 2005
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by delinear
    This has some added security as it will only include pages you specifically add to the $allowed_pages array.
    Wow that's a much better way than I do it.. learn something new every day eh

  • #4
    New Coder
    Join Date
    Jun 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you very much!

    I still have one question. I already included it before so now i have this is a piece of the php file i include:
    Code:
    <table width="200" border="0" cellspacing="0" cellpadding="0">
      <tr bgcolor="#FFFFFF">
        <td width="10" height="20">&nbsp;</td>
        <td width="25" height="20"><div align="center"><img src="images/asp.gif" name="1" width="17" height="16" border="0"></a></div></td>
        <td width="155" height="20" class="style"><a href="index.php?id=asp">Asp</a></td>
        <td width="10" height="20">&nbsp;</td>
      </tr>
      <tr>
        <td width="10" height="20" background="images/content_left_gray.gif">&nbsp;</td>
        <td width="25" height="20" bgcolor="#F0F0F0"><div align="center"><img src="images/c.gif" name="2" width="16" height="16" border="0"></a></div></td>
        <td width="155" height="20" bgcolor="#F0F0F0" class="style"><a href="index.php?id=c">C</a></td>
        <td width="10" height="20" background="images/content_right_gray.gif">&nbsp;</td>
      </tr>
    Like you said with the id i did it with asp and c. and the link goes to the index page. I hope i did that right...

    I have also inserted the php code in the table in the index.php where the different includes should show up and i made an asp.php page but it doesn't work, it gives me the error message that the page could load or doesn't exist

  • #5
    New Coder
    Join Date
    Jun 2005
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh srry it works fine now Thank you very much for helping me with this


  •  

    Posting Permissions

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