Jump to content


Photo

Using inlcude()


  • Please log in to reply
2 replies to this topic

#1 Avendium

Avendium
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 06 June 2006 - 01:54 AM

Ok, im gonna try and simplifiy my explination as much as possible to make sure you guys understand what I want to do. Heres the deal. Im making a site where every aspect of it can be edited from an external file. Before I explain my problem. Im gonna try explain what I want to do.

Heres a text example of how my server is setup right now in terms of folders and php files.
*note, following is not my code, I just used the code quotes to keep the formating.

   
ROOT--------> index.php
              [Folder: System] ------> [Folder: Engine]----------------------->engine.php
                                       [Folder: Modules]------>[Folder: Menu]---->menu.php

So the Url's for the files are:

Short urls examples
index.php
System/Engine/engine.php
System/Modules/Menu/menu.php

Full urls examples
[a href=\"http://www.websiteURL.com/index.php\" target=\"_blank\"]http://www.websiteURL.com/index.php[/a]
[a href=\"http://www.websiteURL.com/System/Engine/engine.php\" target=\"_blank\"]http://www.websiteURL.com/System/Engine/engine.php[/a]
[a href=\"http://www.websiteURL.com/System/Modules/Menu/menu.php\" target=\"_blank\"]http://www.websiteURL.com/System/Modules/Menu/menu.php[/a]

In my engine.php. I have the following example of code.

<? 
$MenuURL = '/System/Modules/Menu/Menu.php'; //Menu Module URL
?>

In my Index.php. I have the following example of code in the header

<? include ('/System/Engine/Engine.php');?>


and then i have this code where i want my menu to appear

<?php include ($MenuURL);?>

This setup works fine. The engine is loaded into the index and then menu.php loads the variable url and the menu shows up. The problem with this however is if i wanted to put the menu in another page I wouldnt be able to because the url in the engine is based from the root of the of the server. Is there a way to make the include() command to be rerouted back to the root of the server and then locate the file from there?

I tried using this:

<?php include ($_SERVER['DOCUMENT_ROOT'].($MenuURL));?>

And it worked on my apache test server but the urls in the source code started from the c:\ all the way to my apache www directory and then adds on the url from the engine to the end of it completing the Url. When I tested this on an online server. It didnt work. What is wrong with the code? Is this even possble to do and if not what do you think is the best way I should go about this in order to get my files working together like so:

[img src=\"http://revonet.org/stuff/leonix/engine.gif\" border=\"0\" alt=\"IPB Image\" /]

Please help, and Thanks.

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 06 June 2006 - 02:36 AM

Wow, I rarely see a question posted like this... Nice [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]

<?php

$file = $_SERVER['DOCUMENT_ROOT'] . '/System/Engine/Engine.php';
include $file;

?>

Should work. Don't use round brackets to group strings, it won't work.
~ D Kuang

#3 Avendium

Avendium
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 06 June 2006 - 08:54 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Wow, I rarely see a question posted like this... Nice [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] [/quote]
I write alot of tutorials [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /] not used to asking questions.

Your solution fixed my problem, Thanks.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users