Get File path using sub-domains

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,
The contain of index.php is:
<? include("database.php"); ?>
<? include("brain.php"); ?>
The problem is, database.php and brain.php located in and

The only way I found to fix the problem was <? include(""); ?>, 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 (, 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
Pedro ChagasWebmasterAsked:
Who is Participating?
upandrun3Connect With a Mentor Commented:
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,
Where are pointing ? Are the files for that subdomain located in ../public_html/example/ or what ?
Pedro ChagasWebmasterAuthor Commented:
Hi, The file (index.php) that will call 'database.php' (with php function include) is located in and database.php is located in the domain (root) like

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
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.

Pedro ChagasWebmasterAuthor Commented:
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 '' 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
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.

Pedro ChagasWebmasterAuthor Commented:
Hi, simple access with ../database.php.

Regards, JC
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.