Jump to content


This topic is now archived and is closed to further replies.


Includes help please...

Recommended Posts

Hey everyone,

Just a quick question I'd like to resolve tonight...

I have an index page that holds the php include script, and pages are called into that. The first page it calls has several links on it, which need to go to other pages in other directories, BUT, here's where the problem is: I don't know how to link to a page in another directory, since simply trying [i]index.php?x=dir1/page[/i] tries loading index.php?x=page and that's it. Is there a way to write a filepath that fixes this problem?

If it helps, a basic look at my directory is:

Main Directory
  - dir1
      - page.php
  - index.php

I hope I've explained my problem sufficiently enough that somebody can explain to me what I need to do! Thanks in advance! :)


Share this post

Link to post
Share on other sites
Urlencode will not help. But what you might want to do is to create an array of all the pages that are in  different directories. The use an if statement to check the page being included if its in the array of pages in different directories. If it is use the path in the array for that page.

Sounds complicated? Its not but very straight forward if you understand arrays. Heres a quick demo of what I mean:

// check that 'page' is set in the url
    // now we setup our array of pages in different folders
    // the following is the format of our array:
    // array([pagename] => array([filename], [path to file]));
    // Our pages array
    $pages = array("about" => array("index.php", "./about/"),
                  "contact" => array("contact.php", "./pages/"),
                  "products" => array("list-products.php", "./shop/")

    // Now we check wether the page needed to be included is in our pages array
    if(array_key_exists($_GET['page'], $pages))
        // now we include our page:
        echo "include '" . $pages[$_GET['page']][1] . $pages[$_GET['page']][0] . "';";
    // if it wasn't we presum its its in the same folder as this script
        echo "include './" . $_GET['page'] . ".php';";

    echo "<br />\n<br />\n";

Include: <a href="?page=about">About page</a> | <a href="?page=contact">Contact page</a> |
<a href="?page=products">Products</a> | <a href="?page=home">Home</a>[/code]

Share this post

Link to post
Share on other sites
Thanks for that! It seems quite straight-forward, actually. I'm a total php noob because I only learn what I need to when I need to use it. Tonight I'm learning about arrays! ;D

Okay, first of all, I'm having a bit of bother about how to load a page called 'gallery.php' as the default page that gets loaded at the start. Basically, what I want to achieve is:

1. index.php loads a text page with links to other pages called 'gallery.php'.
2. gallery.php has many links to pages in many other directories, which will load into index.php.

I could easily achieve this (as I have done already) with a simple iframe, but I don't want the inherent scrollbar and how I got past that in the past was to use a script that set the iframe dimensions to the exact dimension of the various pages it will load. BUT, that only worked in IE. This time, it is very important to me that the site works in Mozilla Firefox and Opera.

Thanks for your help so far, but if anyone can offer any advice about how to go about achieving my plan, I would be very damn grateful! :D

Share this post

Link to post
Share on other sites
so you want the links to open in the same page without reloading the entire page, or does that matter?

Share this post

Link to post
Share on other sites
I'd prefer to have it so that plain text pages will load into the main page (index.php), which holds the quite image-intensive layout design. Is that what you mean? :-\;)

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.