Jump to content

php include used with sub-domain


elmas156

Recommended Posts

Hello everyone,

 

I have a site where the folders are set up in this arrangement:

                           _
ClientsFolder - client1 - | page-folder - pages are here (index.php)
                          |
                          | image-folder - images here
                          |
                          |_include-folder - style.css and database connections here
                                        
                           _
                client2 - | page-folder - pages are here (index.php)
                          |
                          | image-folder - images here
                          |
                          |_include-folder - style.css and database connections here


PageIncludeFolder - include pages here (index.inc.php)

 

The reason my folders are set up this way is because multiple clients will be using my site, but each client will have a customized sub-domain, yet all the code on the pages will be the same.  All of the pages for the clients site are placed in ClientsFolder/client1/page-folder.  Each page in this folder is a page that simply includes an entire page from the PageIncludeFolder.  For example:

 

ClientsFolder/client1/page-folder/index.php

and

ClientsFolder/client2/page-folder/index.php

 

are exactly the same, file, which simply has the following code:

<?php
include("../../../PageIncludeFolder/index.inc.php");
?>

The reason for this is so that I can easily modify all the client sites by only modifying the files that are in the PageIncludeFolder. (Trying to work smarter, not harder!)

 

The images, style.css, and script.js files are called from the index.inc.php, which is included on the index.php page.

 

For example, style.css is located at ClientsFolder/client1/page-folder/include-folder/style.css.  So to link to the .css file, I have the following code in the index.inc.php file:

<link href="../include-folder/style.css" rel="sytlesheet" type="text/css" />

 

And images are linked using code similar to this:

<img src="../image-folder/image.jpg" />

 

Now, when I visit the index.php page by entering the entire url (http://www.mysite.com/ClientsFolder/client1/page-folder/index.php) everything works perfectly.

However, as I stated, each client is being set up with a sub-domain.  Client 1 has the sub-domain of http://client1/mysite.com, which is pointed to http://www.mysite.com/ClientsFolder/client1/page-folder/index.php.  When I try to visit client 1's site using the sub-domain, the index.inc.php page is included perfectly, but the images and the style.css files are not being linked.

 

I know this is kind of confusing, but as you can probably tell, I have spent many, many hours putting this together and now I need help to figure out what is wrong and why certain files are not linking properly ONLY when the page is visited using the sub-domain.  ANY help or suggestions are GREATLY appreciated!  Thanks everyone!

Link to comment
Share on other sites

For anyone else who might have the same problem, I think I've got it figured out:

 

When using php to include files from another folder, you use "../" to go up one step in your folders.  So it will work exactly the way I have described it above.

 

For some reason, when using a sub-domain, you cannot use the "../" method with html to link images or .css file, you have to use the entire url.  So to link to the css file you have to do it this way:

 

<link href="http://www.mysite.com/ClientsFolder/client1/include-folder/style.css" rel="sytlesheet" type="text/css" />

 

That's the way it is working for me anyway.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.