[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Get File path using sub-domains

Posted on 2010-09-22
6
Medium Priority
?
804 Views
Last Modified: 2012-05-10
Hi E's, I have my site in a sub-domain, and some of that contain I want get from the domain, but I don't know the path.
In practice, I have this files located in a sub-domain, example.domain.com/index.php.
The contain of index.php is:
=============================begin
<? include("database.php"); ?>
<? include("brain.php"); ?>
=============================end
The problem is, database.php and brain.php located in domain.com/database.php and domain.com/brain.php

The only way I found to fix the problem was <? include("http://domain.com/database.php"); ?>, but I want to see if it is possible the path don't contain the domain name, because the domain can be a lot of names (domain.com, thedomain.com etc).

I try without sucess, do this kind of paths:
<? include("../public_html/database.php"); ?>
<? include("..home/public_html/database.php"); ?>

What is the path to get a file in domain from sub-domain?

Regards, JC
0
Comment
Question by:Pedro Chagas
[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
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:trencH87
ID: 33737575
Where are example.domain.com pointing ? Are the files for that subdomain located in ../public_html/example/ or what ?
0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 33739000
Hi, The file (index.php) that will call 'database.php' (with php function include) is located in www.example.domain.com/index.php and database.php is located in the domain (root) like www.domain.com/database.php.

I put some images from my hosting file manager for you see the path.

How I call (with php include) the file database.php from a file located in a sub-domain?

Regards, JC
fl1.png
fl2.png
0
 
LVL 4

Accepted Solution

by:
upandrun3 earned 1200 total points
ID: 33739075
Hi joaochagas,

You can try including the full path to those files in those includes:

<? include("/home/wwdablio/public_html/database.php"); ?>
<? include("/home/wwdablio/public_html/database.php"); ?>

That should work, unless there is a permission problem.  Also, the domain and subdomain both have be hosted on the same server. Finally, if safe_mode or openbasedir is on, it may prevent this from happening.

Ideally, if the subdomain and domain are always in relation, then it's generally better for portability reasons to use a refenced path, like what you had above. My example will let you know if it works through or if PHP's protections may be getting in the way of doing a cross site include like what you want to do.

Hope this helps,
Pete
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:Pedro Chagas
ID: 33739200
Hi @upandrun3, your solution work.
Don't have a better way to do this? Like I tell before I don't want to see the domain, because maybe I will use the same code for different domains and accounts. If I have the account 'newaccount.com' the account will call newaccount and the include function will change for <? include("/home/newaccount/public_html/database.php"); ?>
The only way possible for do this but not very practical is something like this:
<?
$domainwithoutdotcom = thenameofaccount;
include("/home/$domainwithoutdotcom/public_html/database.php"); ?>

Don't have a simple way to do this without domain or account name?

Regards, JC
0
 
LVL 4

Expert Comment

by:upandrun3
ID: 33739443
Hi JC,

What's the full server path to the main domain site and what's the full server path to the subdomain that you're doing the include from?

From your images, I can tell the main domain is in the folder /home/wwdablio/public_html.

Where is the subdomain located? If there is a consistent structure relationship between the main domain files and the subdomain files, we can construct an include string that would work without needing the domain.

Thanks,
Pete
0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 33739820
Hi, simple access with ../database.php.

Regards, JC
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
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.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

650 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