Forum Moderators: coopster
I will never understand regular expressions :/
any help?
Including files and opening directories work best when you set path like $dir = $_SERVER['DOCUMENT_ROOT']./folder/ (imo)
but this only works when you dont use subdomains in the url, only normal www.example.com/subdomain naming style URLs
in this case $dir could be: home/user/public_html/folder
if one uses subdomain.example.com instead, the $dir will be
home/user/public_html/subdomain/folder, as the $_SERVER['DOCUMENT_ROOT'] is altered by using the different URL
you are aware that $_SERVER['DOCUMENT_ROOT'] returns a local path to the www root (normally) of the website right? What good is $_SERVER['SERVER_NAME'] gonna do me then?
Because it is you that has a misunderstanding, my friend :)
Are you aware, that this ...
However, using the url not like http://www.example.com/subdomain/ but like [subdomain.example.com...] alters the $_SERVER['DOCUMENT_ROOT'] variable and includes the subdomain name at the end of the variable.
... is not a true statement? Example:
<VirtualHost 192.168.1.1:80>
ServerName subdomain.example.com
DocumentRoot "/www/example/subdomain"
</VirtualHost>
<VirtualHost 192.168.1.1:80>
ServerName www.example.com
ServerAlias example.com *.example.com
DocumentRoot "/www/example/root"
</VirtualHost>
http://subdomain.example.com
$_SERVER['DOCUMENT_ROOT']of
/www/example/subdomain
... but ...
A request to any of the following:
http://example.com
http://www.example.com
http://someothersubdomain.example.com
$_SERVER['DOCUMENT_ROOT']of
/www/example/root
Thereby the reasonable request for clarification.
Yes, using $_SERVER['DOCUMENT_ROOT'] is ideal for setting paths for includes relative to the DocumentRoot and I use it exclusively. However, how are you going to know that you are in a subdomain versus your 'root' domain?
Possible answer: have a look at the $_SERVER['SERVER_NAME']
I'm guessing your situation is that you have some documents within your 'root' domain folder that you want to include [php.net] when you are active in a subdomain. Is this a true statement?
I need this basically for includes and functions which need access to certain folders on the site.
For example I have a php file which draws a table of smilies one can use. The smilies can be used in the forums, for which Ive set up a subdomain, but also for comments on a couple of other subdomains on my site.
so I really need to simply strip out the subdomain from the local path :)
also:
... is not a true statement? Example:A request to [subdomain.example.com...]
returns $_SERVER['DOCUMENT_ROOT'] of /www/example/subdomain
isnt that what I said and what prevents this from working right?
... but ...
A request to any of the following:
http://example.com
http://www.example.com
[someothersubdomain.example.com...]
returns $_SERVER['DOCUMENT_ROOT'] of /www/example/root
well, a request to [someothersubdomain.example.com...] will return $_SERVER['DOCUMENT_ROOT'] of /www/example/someothersubdomain, thats for sure
I could hardcode the local web root for the site, but I really dont want this for portability, Im forseeing moving hosts a couple of times.
I just need something that will always return the real web root and since it does not exist, I need a regexp to strip out possible subdomains in that path :)
I could hardcode the local web root for the site, but I really dont want this for portability, Im forseeing moving hosts a couple of times.
That's where I figured you headed here. I believe what you are really describing then is a common includes directory for use in all your sites. Create yourself a
commonincludes directory. Then, in your include_path all you have to do for the sites that use the common includes is append that path. For example, lets say we have three sites setup, first is the 'root' site, and then two subdomains.
www.example.com
subdomain.example.com
anothersubdomain.example.com
We need includes paths for all these. Some will be specific to each domain, but one will contain all the functions and included files that we want to share across all the domains. So we create a directory structure for our includes:
/www/example/includes/root
/www/example/includes/subdomain
/www/example/includes/anothersubdomain
/www/example/includes/common
Store all your commonly shared functions (non site-specific) in the common includes directory. Now, in all your sites that require these includes you append the path. To do so in your Apache
httpd.confit will look something like this:
<VirtualHost 192.168.1.1:80>
ServerName subdomain.example.com
DocumentRoot "/www/example/subdomain"
php_value include_path ".:/path/to/PEAR:/www/example/includes/subdomain:/www/example/includes/common"
</VirtualHost>
<VirtualHost 192.168.1.1:80>
ServerName anothersubdomain.example.com
DocumentRoot "/www/example/anothersubdomain"
php_value include_path ".:/path/to/PEAR:/www/example/includes/anothersubdomain:/www/example/includes/common"
</VirtualHost>
<VirtualHost 192.168.1.1:80>
ServerName www.example.com
ServerAlias example.com *.example.com
DocumentRoot "/www/example/root"
php_value include_path ".:/path/to/PEAR:/www/example/includes/root:/www/example/includes/common"
</VirtualHost>