homepage Welcome to WebmasterWorld Guest from 54.204.168.212
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / WebmasterWorld / New To Web Development
Forum Library, Charter, Moderators: brotherhood of lan & mack

New To Web Development Forum

    
Using includes on subdomains
how to use php includes in subdomains
sportsguy

5+ Year Member



 
Msg#: 2992 posted 12:36 am on May 28, 2006 (gmt 0)

OK, I rarely post here, but read often.

SUMMARY:

How do I use includes in my pages residing in the subdomain of my main site? Naturally the includes work fine on the main domain, but I cannot figure out how to get includes to work for the subdomain pages - please read on for more details which explain what I have already tried.

THE FULL MAGILLA:

Now, I'm posting this in this section because I'm by no means a web developer, programmer, sysadmin, etc.

I do have a couple of small, active sites which hum along, and I've learned a lot in building them, but this is my first foray into the world of subdomains. *shudder*

My problem is this:

I am trying to use php includes in the subdomain pages - but cannot get them to show on the live page. :(

Some back-ground:

1 - I'm on a virtual dedictaed server, so I have full access to "my" server.
2 - Obviously it's running php (Linux/Apache - I never know how to properly say this like "It runs Windows") - (I am a dumbass, I know)
3 - All includes work fine on the main website

Now, I have been at this for about 6 hours so far today and here's a run-down on what I've tried (and what has failed). I'll try to do this justice as I know a wrong character or misplaced space can cause things to go awry... (f-ing .htaccess files! I love them now, but hated them for about 3 hours one cold, dreary Sunday... LOL)

The main website is structured as such:

http://www.domain.com/file-name.html

Includes reside as:

http://www.domain.com/includes/nav.php

Images, same dealio...

Now, on the main domain, I use the following code to bring in the includes:

<?php include('includes/test_header.php');?>

Brings it in on a "relative path", if I'm using the correct terminology there.

Now, dropping this code into the test page (http://subdomain.domain.com/template-page.html) I have in the subdomain (http://subdomain.domain.com/) nets me squat.

I have the following folders created in the subdomain:

/includes/
/images/

Now, the confusing part for me is that I do actually have the php files I want included inside this /includes/ folder in the subdomain. If I type the direct path for the file into the address bar, it shows up nicely.

Images are pulled into the subdomain test page properly (from the /images/ folder in the subdomain).

I have tried the following combinations of include code and more - all of which have failed to be successful (the actual file I'm testing for is named "sc_header.php"):

<?php include("subdomain.domain.com/includes/sc_header.php");?> (quotes, no "http://")

<?php include("http://subdomain.domain.com/includes/sc_header.php");?> (quotes & "http://")

<?php include('subdomain.domain.com/includes/sc_header.php');?> (apostrophies, no "http://")

<?php include('http://subdomain.domain.com/includes/sc_header.php');?> (apostrophies & "http://")

<?php include("http://www.domain.com/includes/sc_header.php");?> (tried calling from the main domain's include folder - no joy - tried this with quotes & apostrophies, with and without the "http://")

<?php include('domain.com/subdomains/nameofsubdomain/httpdocs/includes/sc_header.php');?> (this one with quotes and apostrophies and every permutation of inclusion or removal of listed items in the path - with and without "httpdocs", for example.

Heck, I even just tried dropping the file into the root of the subdomain and calling it from there - again, zip.

I've searched threads here, at php.net and generally through Google today - nothing helped point me in a direction that worked. I did find some ideas of things I hadn't tried, but when I did try them, nada.

I came across some references to "cgi-bins", but not being a programmer, etc., I have no clue what they are, how to set them up or how to use them. I'm hoping for a simple solution to this problem, rather than a lessons in yet another new item to learn.

So, there we go folks - I'll throw myself at your mercy.

As I mentioned near the beginning of this post - I am NOT a web developer, programmer or sysadmin - it's been a long, frustrating journey to learn what I know on my own, and I am still firmly encamped in my "Noob" status.

I'd appreciate any partical suggestions and idea that are directly applicable to solving this problem.

I clearly am missing something in my understanding of what works with subdomains... :(

 

encyclo

WebmasterWorld Senior Member encyclo us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 2992 posted 1:25 am on May 28, 2006 (gmt 0)

With PHP, the include path is in relation to the server root (ie. the filesystem). So you can link via the full path from / like this (adjust to your server setup):

<?php include('/home/username/public_html/nameofsubdomain/httpdocs/includes/sc_header.php'); ?>

Using this method will work well when you are sharing the same include files across subdomains. Is that what you were looking for?

suzie250

5+ Year Member



 
Msg#: 2992 posted 3:02 am on May 28, 2006 (gmt 0)

Try this:
<?php include("includes/sc_header.php");?>

You dont show in your examples that you have tried that.

This example that you provided should also work
<?php include ("http://subdomain.domain.com/includes/sc_header.php");?>

If you have a redirect from non www to www set up for the subdomain, that could be causing a problem.

If the server cannot find the include file, you should be getting an error message stating so. You didn't say
if you were getting an errors or just a blank space.

sportsguy

5+ Year Member



 
Msg#: 2992 posted 4:27 pm on May 28, 2006 (gmt 0)

Thanks guys.

I'll work on those suggestions.

Encyclo - I can't really say if that's in fact what I'm after, though I was hoping to set up individual includes for subdomain, rather than sharing the includes form the main-domain itself. Not sure I really need to set them up as searate, but I'd rather do it this way now and manage the ads through Adwords & categories there, than add the few hundred new pages and realize I need to edit them all again to make a change. ;)

I suspect in the future - since the content is related, but different (automotive, but different topics within that vertical, for example) - I'll want to be able to manage the ad spaces independantly.

I'll try your suggestions as soon as I can figure out what parts of that string are and where to find them...

Suzie - I think I did actually try that combo, but I'll run it again just to be certain.

...and I do have the .htaccess file dealing with the canonicalization issue, so that could indeed be causing an issue.

I am actually just seeing blank spaces as opposed to any error messages.

Perhaps twiddling with the .htaccess files to allow access to subdomain.domain.com specifically will cure this problem - the real stumper for me was that the direct path didn't work.

encyclo

WebmasterWorld Senior Member encyclo us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 2992 posted 4:38 pm on May 28, 2006 (gmt 0)

If each subdomain has unique include files, then you can try this:

<?php include($_SERVER["DOCUMENT_ROOT"]."/includes/nav.php"); ?>

This will save you from specifying the exact path to the document root each time.

sportsguy

5+ Year Member



 
Msg#: 2992 posted 1:56 pm on May 29, 2006 (gmt 0)

If each subdomain has unique include files, then you can try this:

<?php include($_SERVER["DOCUMENT_ROOT"]."/includes/nav.php");?>

This will save you from specifying the exact path to the document root each time.

OK, I tried this - again, didn't work. :(

I wasn't sure if i should have left it as is (using the actual words "SERVER" & "DOCUMENT_ROUTE" so I tried it that way (didn't work) and then changes those words out for the nameserver data and, well, the actual document route - again, didn't work.

The question I have is this:

Should I have swapped out the words for the nameserver data and doc-root data? (Told you I had limited knowledge in these areas... ;) )

...and how do I find the actual document root? In my failed attempt, I used http://subdomain.domain.com/includes/ as the doc-root (tried http://subdomain.domain.com/ with no luck as well).

And I might as well just ask this. In this post you made earlier Encyclo:

<?php include('/home/username/public_html/nameofsubdomain/httpdocs/includes/sc_header.php');?>

What are:

~ home
~ username
~ public_html

...and how/where do I find this data for myself (about myself)?

I'm running a virtual dedicated server, if that matters...

Thanks for your help with this. It's folks such as yourself and suzie that have helped and allowed me to grow my knowledge over the years - I appreciate it.

sportsguy

5+ Year Member



 
Msg#: 2992 posted 3:00 pm on May 31, 2006 (gmt 0)

Any more thoughts or help gang? Still stuck and after trying everything listed here (that I understood), I'm still at a stand-still. :(

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 2992 posted 3:16 pm on May 31, 2006 (gmt 0)

The offering here should indeed work, and it is
DOCUMENT_ROOT, not DOCUMENT_ROUTE.
<?php include($_SERVER['DOCUMENT_ROOT'].'/includes/nav.php');?>

You can find these variables by running a simple php script such as
<?php 
phpinfo() [php.net];
?>

Just open up your favorite editor and save that little snippet of code as a .php file and FTP it to your server. Open the link in your browser. This will show you all kinds of information about your server. The names in the path were examples shown by encyclo. Your server-specifics will be listed in that phpinfo script output.

suzie250

5+ Year Member



 
Msg#: 2992 posted 3:27 pm on May 31, 2006 (gmt 0)

Put

error_reporting = E_ALL

at the top of one of your include pages after your first opening php tag. See if that will pick up any errors.

sportsguy

5+ Year Member



 
Msg#: 2992 posted 11:28 pm on Jun 7, 2006 (gmt 0)

Still no luck gang - I've tried everything suggested in here and nothing works.

I simply cannot believe it's THIS difficult to use includes in a subdomain.

What am I missing... :(

suzie250

5+ Year Member



 
Msg#: 2992 posted 2:34 am on Jun 8, 2006 (gmt 0)

Is php working? (I've never worked with a virtual dedicated server, but maybe php isn't set up for the subdomain?)

If you are redirecting from subdomain.com to www.subdomain.com, did you try the include with www?

Is the page calling the include a php file?

Maybe something in the header file that you are calling is causing the problem. Have you tried to include a very simple file?

sportsguy

5+ Year Member



 
Msg#: 2992 posted 10:53 pm on Jun 8, 2006 (gmt 0)

Not sure how it wouldn't be set up for the subdomains - but then again, I'm still new to managing servers, so...

The page calling the include is an html file. The include itself is a .php - Not sure what the differences would be, as I'm following the exact same pattern for the subdomain that currently works on the main website.

Here's a snapshot of what my phpinfo page is telling me:

PHP Core
Directive Local Value Master Value
allow_call_time_pass_referenceOffOff
allow_url_fopen OnOn
always_populate_raw_post_dataOffOff
arg_separator.input &&
arg_separator.output &&
asp_tags OffOff
auto_append_file no valueno value
auto_prepend_file no valueno value
browscap no valueno value
default_charset no valueno value
default_mimetype text/htmltext/html
define_syslog_variables OffOff
disable_classes no valueno value
disable_functions no valueno value
display_errors OffOff
display_startup_errors OffOff
doc_rootno valueno value
docref_extno valueno value
docref_rootno valueno value
enable_dl OnOn
error_append_stringno valueno value
error_log no valueno value
error_prepend_stringno valueno value
error_reporting 20472047
expose_php OnOn
extension_dir/usr/lib/php4/usr/lib/php4
file_uploads OnOn
gpc_order GPCGPC
highlight.bg #FFFFFF#FFFFFF
highlight.comment#FF8000#FF8000
highlight.default#0000BB#0000BB
highlight.html #000000#000000
highlight.keyword#007700#007700
highlight.string#DD0000#DD0000
html_errors OnOn
ignore_repeated_errorsOffOff
ignore_repeated_sourceOffOff
ignore_user_abortOffOff
implicit_flushOffOff
include_path.:/usr/share/pear.:/usr/share/pear
log_errors OnOn
log_errors_max_len10241024
magic_quotes_gpcOffOff
magic_quotes_runtimeOffOff
magic_quotes_sybaseOffOff
max_execution_time3030
max_input_time6060
memory_limit32M32M
open_basedir/var/www/vhosts/domain.com/subdomains/name-of-subdomain/httpdocs:/tmpno value
output_bufferingno valueno value
output_handler no valueno value
post_max_size 8M8M
precision 1414
register_argc_argvOnOn
register_globalsOffOff
report_memleaks OnOn
safe_mode OnOn
safe_mode_exec_dirno valueno value
safe_mode_gidOffOff
safe_mode_include_dirno valueno value
sendmail_fromno valueno value
sendmail_path/usr/sbin/sendmail -t -i/usr/sbin/sendmail -t -i
serialize_precision100100
short_open_tagOnOn
SMTPlocalhostlocalhost
smtp_port2525
sql.safe_modeOffOff
track_errorsOffOff
unserialize_callback_funcno valueno value
upload_max_filesize2M2M
upload_tmp_dirno valueno value
user_dirno valueno value
variables_orderEGPCSEGPCS
xmlrpc_error_number00
xmlrpc_errorsOffOff
y2k_complianceOnOn

Anything in there look off? (Sorry the spacing is wonky...)

abbeyvet

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 2992 posted 12:27 am on Jun 9, 2006 (gmt 0)

The page calling the include is an html file

Is the server parsing html files for PHP? If not, and if you don't know then it is probably it is not, then that is your problem.

Rename the file with a .php extension and see if that works.

PHP includes can only be used in pages capable of parsing them, which generally means .php files unless you have set things up specially so that it parses files with other extensions.

sportsguy

5+ Year Member



 
Msg#: 2992 posted 1:53 pm on Jun 9, 2006 (gmt 0)

I thought I covered that combo during the past 2 weeks of chasing this abbey, but, I'll try it today to make certain - I really don't care whether the pages are html or php, so if this works - a case fo beer for you! :)

sportsguy

5+ Year Member



 
Msg#: 2992 posted 5:11 pm on Jun 9, 2006 (gmt 0)

So I tried both combos:

1 - page and include file both as .html
2 - page and included file both as .php

Didn't make any difference at all...

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / WebmasterWorld / New To Web Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved