Solved

Including a file on a page - Same page, Different URLs

Posted on 2006-10-30
5
168 Views
Last Modified: 2013-11-18
Hello Everybody!

I have a situation in which I need to include a file on a single page that has 2 different URLs and path depths.

For example:
Include File: http://www.mysite.com/include/include.inc
URL 1 = http://www.mysite.com/mypage/index.php
URL 2 = http://mypage.mysite.com/index.php

I know I can include a file absolutely by using $_SERVER['DOCUMENT_ROOT'], but that does not work in the URL 2 situation (as the DOCUMENT_ROOT includes the "mypage" directory in its output, essentially then looking for the file in root/mypage/include/include.inc instead of root/include/include.inc).

Is there any straightforward way to overcome this? This is within a larger system using templates, so I don't have a lot of leeway in my programming.

Thanks!
Carlene
0
Comment
Question by:carlenevs
5 Comments
 
LVL 7

Accepted Solution

by:
CraigHarris earned 250 total points
ID: 17838240
If it's part of a larger system you should really have some structured way of managing paths etc -- either a config file with a list of paths in it, or a database storing the equivalent.

Why can't you use the absolute filesystem path? - ignore the document root, but don't try touching files outside such if open_basedir is set.

e.g. both can
   include_once(/usr/local/www/root/include/include.inc);

regardless of the path within $_SERVER['DOCUMENT_ROOT']

However, I am assuming that both sites have access to the folder you are trying to get the file from - otherwise your out of luck -- though you can inlcude via a URL if you really need to -- this is not exactly secure/safe in most cases though!
0
 
LVL 3

Expert Comment

by:www-i-p-mu
ID: 17841707
me i'll put like this

include('http://www.mysite.com/mypage/index.php');


include('http://mypage.mysite.com/index.php');


Good luck!!
0
 
LVL 4

Expert Comment

by:KellyCraig
ID: 17851754
Wait.
So, why are the paths not relative?
Both of those URLS point to the same folder no>?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question