Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-10-30
5
Medium Priority
?
173 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 7

Accepted Solution

by:
CraigHarris earned 1000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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.
This article discusses how to implement server side field validation and display customized error messages to the client.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

722 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