neskaya
Follow [ bookmark livejournal facebook twitter rss stumbleupon ]
Log in to download layouts, skins, and emoticons. Register?

Designs

Web Templates
LJ Layouts
phpBB3 Skins

Graphics

Avatars
Textures
Buttons
Emoticons
Pixels
Fonts

Misc & Fun

Quizzes
Tutorials
Interactive

Community

Forums
Rotation

Site

FAQ & Contact
Links

Affiliates

Komet Tails
Smile Scan
Dragonrain

PHP Tutorial: Include Files from a Subdomain

If you want to use the PHP include() function to include any file from a subdomain or a directory, you can always use $_SERVER['DOCUMENT_ROOT'] in the include, but that tends to raise some problems from my experience. This is an alternative to using document_root that works very well, especially when you need to include from a subdomain or directory.

First, you need to find the path to the document root on your domain. This can be done quite simply: induce a PHP include error. If you include a non-existant PHP file, and then run the file, you should get an error that says "Warning: [some reason] in /path/to/the/file/you/are/including/from.php on line #." That path is the one you'll be using in all your includes!

For example, my header and footer includes are hypothetically in a directory called includes. You could access it by typing in http://neskaya.net/includes/header.php in your browser, but you can't use remote URLs in the include() function. Let's say I ran an erroneous include from my index.php file on my main site - I would get the error in the path of /home/username/public_html/index.php.

Then I would know what the path is to my include files - so if I want to include the header from anywhere - including from a subdomain - I would type:

<? php include ("/home/username/public_html/includes/header.php"); ?>

And viola! Just note: your path may be different from mine! It can include localhost instead of home, or any variation of. That's why it's good to find out for yourself.