Solved

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

Posted on 2006-10-30
5
170 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

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.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

713 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