Jump to content

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! :)

Chris
Link to comment
https://forums.phpfreaks.com/topic/13683-includes-help-please/
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:
[code=php:0]<?php

// check that 'page' is set in the url
if(isset($_GET['page']))
{
    // 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
    else
    {
        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]
Link to comment
https://forums.phpfreaks.com/topic/13683-includes-help-please/#findComment-53273
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

EDIT:
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
Link to comment
https://forums.phpfreaks.com/topic/13683-includes-help-please/#findComment-53583
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.