Welcome to WebmasterWorld Guest from 18.104.22.168
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. :(
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:
Includes reside as:
Images, same dealio...
Now, on the main domain, I use the following code to bring in the includes:
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:
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... :(
<?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?
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.
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.
If each subdomain has unique include files, then you can try this:
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:
...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.
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?
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:
Directive Local Value Master Value
auto_append_file no valueno value
auto_prepend_file no valueno value
browscap no valueno value
default_charset no valueno value
disable_classes no valueno value
disable_functions no valueno value
doc_rootno valueno value
docref_extno valueno value
docref_rootno valueno value
error_append_stringno valueno value
error_log no valueno value
error_prepend_stringno valueno value
output_bufferingno valueno value
output_handler no valueno value
safe_mode_exec_dirno valueno value
safe_mode_include_dirno valueno value
sendmail_fromno valueno value
sendmail_path/usr/sbin/sendmail -t -i/usr/sbin/sendmail -t -i
unserialize_callback_funcno valueno value
upload_tmp_dirno valueno value
user_dirno valueno value
Anything in there look off? (Sorry the spacing is wonky...)
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.