Solved

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

Posted on 2006-10-30
5
166 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
Comment Utility
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
Comment Utility
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
Comment Utility
Wait.
So, why are the paths not relative?
Both of those URLS point to the same folder no>?
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now