Php issue

software development

#1

I’ll admit, I’m not the most experienced or knowledgeable about PHP, so please bear with me on this.

I reciently moved my website and all it’s little sub-domain friends over to Dreamhost, and am having some issues with a script I wrote. On one of my sub-domains, I have a filein the main folder that is accessed by every other php file in that domain. I did it this way so I didn’t have a lot of repitition in my site, and all I’d have to do to make a directory available for viewing would be to drop the generic index.php file into it. I wouldn’t even have to modify the file to adjust the …/'s so that it could access the right page.

Say the home directory of a sub-domain was in directory /dir. I’ve got my sort.php file in that directory. Now say directory /dir/newDir/myDir was created for some reason, all I’d have to do would be to drop a generic index.php file into that directory, and it’d be able to display everything perfectly, accessing sort.php from /dir easy as pie.

Now, in theory I should be able to just replace the name of the home directory from my old server with the name of the home directory on this new server, but for the life of me, I can’t get it to work.

Maybe I did something wrong here, I don’t know. It took me quite a while to get the kinks worked out of this, and I’d like to not have to reinvent the wheel here.

<? $directory_name = getcwd(); //length of home directory to offset the replacement of the string. $offset = strlen("public_html"); //include statement include substr_replace($directory_name, "/sort.php", (strrpos($directory_name, "public_html") + $offset)); ?>

What keeps happening, though, is that the script will work just fine in the main directory as is (obviously with the new home directory put in place of “public_html”), but if I drill down a level in the tree to a folder in that directory, I have to modify the script to get it to work (I have to take out the “+ $offset” from the last line). If I drill down another level, I can’t get it to work at all to save the life of me.

So…advice?


#2

Let me get this straight. You are trying to “include” the same file on every page of your site, but set it up in such a way that you don’t have to keep editing the path?

If that’s the case, consider using the following PHP environment variable:$_SERVER['DOCUMENT_ROOT']You can find more about this on this page of the wiki.


Simon Jessey
Keystone Websites | si-blog


#3

Correct.

I also figured something else out. trying to find the position of the string in the directory is what’s messing up.

I’ll take a look at your suggestion, though. It’ll probably be a lot easier than what I was working on.

As a side note, what version of PHP do we have access to?


#4

You have these choices (available in the Control Panel):

  1. PHP 4 as an Apache module
  2. PHP 4 as a CGI application
  3. PHP 5 as a CGI application

The latter has been setup with so that things like magic quotes and registered globals are disabled.


Simon Jessey
Keystone Websites | si-blog