Re: root_url and http_host

Joe Stewart <[email protected]> Mon, 7 Apr 2003 14:29:40 -0500
Newsgroups gmane.comp.cms.phpslash.devel
Message-ID <[email protected]>
On Thu, Dec 19, 2002 at 11:32:57AM -0600, Joe Stewart wrote:
> 
> Mike Gifford and I have been discussing something that I've brought up 
> before.
> 
> Whether root_url should just be the relative path and not include the full 
> url.
> 
> In short to paraphrase Mike:
> 
> "Would it just be easier to specify a host:
>         $_PSL['http_host'] = $_ENV['HTTP_HOST'];
> 
> & have the root url be somthing like this (if it's in a subdirectory of
> the site):
>         $_PSL['rooturl'] = '/public_html';"
>

I played around with having config.php detect the basedir and rooturl 
if it is not given in config.ini.  This only left the db variables and 
dir.include.  I also played around with setting up variables for the 
domain name and host name.

Worked OK except for the scripts in the admin directory.  The rooturl 
changed and screwed it all up.  The rooturl has /admin appended.  Then 
adminurl appends /admin again.  Anybody got any good ideas?  I sure 
don't.

Joe

// basedir -> complete filesystem path to the pages
if(empty($_PSL['basedir'])) {
   $_PSL['basedir'] = getcwd(); 
}

...skip...

// rooturl -> The base URL for the PHPSlash site.
if(empty($_PSL['rooturl'])) {
   $url = parse_url($_SERVER['REQUEST_URI']);
   $pathinfo = pathinfo($url['path']);
   $_PSL['rooturl'] = $pathinfo['dirname'];
}

// root.http_host -> The hostname of the PHPSlash site.
if(empty($_PSL['root.http_host'])) {
   $_PSL['root.http_host'] = $_SERVER['HTTP_HOST'];
}

// root.domain -> The domain for the PHPSlash site.
if(empty($_PSL['root.domain'])) {
  $server_parts = explode('.', $_PSL['root.http_host']);
  $count = count($server_parts);
  if($count > 1) {
     $_PSL['root.domain.tld'] = $server_parts[$count-1];
     $_PSL['root.domain.name'] = $server_parts[$count-2];
     $_PSL['root.domain'] =  $_PSL['root.domain.name'] .".". $_PSL['root.domain.tld'];
      unset($server_parts[$count-1]);
      unset($server_parts[$count-2]);
      $_PSL['root.domain.host'] = implode('.', $server_parts);
  } else {
     // no tld - like localhost
     $_PSL['root.domain.tld'] = '';
     $_PSL['root.domain.name'] = $_PSL['root.http_host'];
     $_PSL['root.domain'] = $_PSL['root.http_host'];
     $_PSL['root.domain.host'] = '';
  }
}

 
> I always just do the rooturl as shown above.  There a few templates that I 
> either have to add the host or {SITE_HOST}.  This is how phpslash.org and 
> phpslash.sf.net generate correct links  on one installation.
> 
> Are there still any browser considerations?  I believe NS4 will look up 
> the url again for full urls and not relative.
> 
> Any input?
> 
> Joe
> 


-------------------------------------------------------
This SF.net email is sponsored by: ValueWeb: 
Dedicated Hosting for just $79/mo with 500 GB of bandwidth! 
No other company gives more support or power for your dedicated server
http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/