Solved

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

Posted on 2006-10-30
5
167 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

809 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