How to use include_once in php with subdomains

Hello folks I have a file in and would like it to be used in using include_once How can I achieve this?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
Just use the root-relative version of the path and filename.
include_once "/user/classes/check.class.php";

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Julian HansenCommented:
The include function doesn't know about domains or sub-domains. If your sub-domain is hosted on different server say then include won't work (unless the PHP setting allow_url_include is enabled - which it shouldn't be).

So, assuming they are on the same server then as Dave pointed out using a local path to the file will allow you to include that file.
Folder structure
      Main Domain
      Sub Domain

Open in new window

Then in index.php the relative path
include_once(../Main Domain/Classes/check.class.php');

Open in new window

Or the absolute path
include_once('/Websites/Main Domain/Classes/check.class.php');

Open in new window

Ray PaseurCommented:
Sidebar note:  You may also want to know about this function:

And if you want to write your code in a way that allows for cross-platform functionality, consider using the context-aware predefined constant: DIRECTORY_SEPARATOR
Ray PaseurCommented:
I don't know about the soon-to-be-extinct list.  My use of PHP goes back to 1999, so I encountered PHP on Windows 98, 2000, XP, ME, etc.  I have encountered the '/' problem in the past, when building a church web site circa 2000, and that was when I started using the constant.  Never looked back.
Ray PaseurCommented:
I can't remember the exact timeline.  I changed to DIRECTORY_SEPARATOR long ago because the '/' did not work as desired on Windows hosting.   I can't really say when Microsoft made a change because DIRECTORY_SEPARATOR has worked perfectly from day one, and I never had any reason to change back.  IIRC, this was in the days of PHP4, but it's been a long time.

This page has some copyright information that seems to point to 2004, since PHP 4.0.6.  So I guess Microsoft changed behaviors some time after that.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.