Please note!

This is an archived, inactive copy of
"Dynapfffffff~~~"

Please do not link to this page.


December 27, 2005

Dynapfffffff~~~

Posted by bopuc at December 27, 2005 11:02 PM

Remember I asked about "when was the last time you wrote out an entire webpage" a few weeks back?

Good lord that was still in this same month! So much has happened since then... I remember discussing this at Laika with Karl even! A lifetime ago...

Anyways, sort of lost in that entry was the point that I haven't built a whole website by hand in ages. For the last few years it's due to all these fancy CMS we now have, but even before that I had my own little PHP-based package which allowed me to build entire websites, navigation and infrastructure and plumbing and everything, in minutes. Set it up, put all the content in, move stuff around until "the client" is happy with the architecture.. then skin it. (Its predecessor was hacked together with xSSI variables!)

I have to put up a whole site pronto for something very important. I just tried setting up my little wonder on two different servers (one being "the client's") and it unceremoniously failed. These high-falutin' fancy hosting packages break when you ask for $_SERVER['DOCUMENT_ROOT'], which means I seem to be shit outta luck.

I am faced with the prospect of a ... gulp... static website! Argh!! Over my dead body.

Adriaan, we gotta fix yer goddamn server. ;p

Update:
Just quickly, here are four totally different paths on the same system all supposedly poitning to the same "place". The first three are available to PHP and th efourth is what I see in my SFTP client:

  DOCUMENT_ROOT = /home/www/htdocs
SCRIPT_FILENAME = /home/www/vhosts/name.com/_/test.php
       __FILE__ = /home/www/vhosts/name.com/www/test.php
           SFTP = /home/name/web/www/
Obviously the next step is to actually try each one, but eh, I'm going to bed now. ;)

Comments

Perhaps it's because I don't know better, but I never trusted $_SERVER["DOCUMENT_ROOT"]. I think it may not work in a virtual hosting environment, and it doesn't exist in IIS either.

What I usually do is switch on $_SERVER["SERVER_NAME"] and set my own root (etc.) global variables depending on the server.

For example:

switch ($_SERVER["SERVER_NAME"]) {
  case "localhost":
    // My local environment
    $GLOBALS["C_sToRoot"] = "/thesite/";
    $GLOBALS["C_sToRootServer"] = "e:/web/thesite.com/";
    break;
  case "thesite.com":
  case "www.thesite.com":
    // The live site
    $GLOBALS["C_sToRoot"] = "/";
    $GLOBALS["C_sToRootServer"] = "/home/thesite/public_html/";
    break;
}

Posted by: Patrick at December 28, 2005 12:07 AM

Try using .. "$_ENV" instead ? Have you tried the phpinfo() function ?

Posted by: steve bissonnette at December 28, 2005 11:53 AM

Hehehe, thanks guys but I was just being dramatic. I know what I need to find in order for it to work for me, just didn't have the time at the moment and felt like ranting. ;)

Patrick, thanks for that code, very clever! It would fit nicely in my bootstrap file but it doesn't help me with the include I need to make on every single page of the site (I use the filesystem as the content database. ;)

:D

Posted by: Boris Anthony at December 28, 2005 12:08 PM

Man, you're making an elephant out of a mosquito. I already told you yesterday to take the path from either SCRIPT_FILENAME or __FILE__ which are actually both the same and give you the server path. The path you see in ssh is the "physical" path, which you shouldn't rely on for your includes.

Never rely on DOCUMENT_ROOT on a server that hosts more than one domain.

Posted by: Adriaan at December 29, 2005 02:01 AM

cryin wolf eh !! ;-)

Posted by: steve at December 29, 2005 08:00 PM

naaaah just a big baby ;)

Posted by: Boris Anthony at December 29, 2005 08:04 PM

So it seems I am out of luck this time. None of the other easily available paths will do the trick. The key here is that I have a site consisting of an actual file-system. Every file, in its directory and subdirectory contains an initial include(); directive which needs to go fetch the bootstrap file. The beauty of using DOCUMENT_ROOT is that i don't have to edit the include path on all those files.

And Ado, saying "never rely on DOCUmENT_ROOT on a server that hosts more than one domain is bull. I have been using this code for over 6 years, on hundreds of different hosts, all of them shared servers, and I have never had this problem. Basically, I don't know how yer setup is done, but it is wrong somewhere since DOCUMENT_ROOT should point to the this domain's web root. Always does. ;)

Posted by: Boris Anthony at January 2, 2006 02:49 PM