PHP Server Paths (Probably OT)


D

dorayme

On a Unix server, including the server on my Mac, you can use

<?php include ($_SERVER['DOCUMENT_ROOT'].'/includes/footer.inc');
?>

in any html doc at any level (at least at any level at or below
the normal /public_html) and the footer appears fine in any
browser and with the folder "includes" (containing the footer
markup) at almost any level.

In order to get php includes working on a Windows server, I
manage by stating the detailed path to the folder. This involves
more careful vetting of all the paths in the various folders and
sub folder. It would be nice to have some construction that
worked like with a Unix server. Any suggested strategies please?

(I post here rather than PHP ng because they seem altogether too
technical for it to be useful to me... though I might try. I
think I may have asked something similar in the past but the fact
is I am no nearer a solution. Just be a bit neater not to have to
vet all the paths...)
 
Ad

Advertisements

R

Rik

On a Unix server, including the server on my Mac, you can use

<?php include ($_SERVER['DOCUMENT_ROOT'].'/includes/footer.inc');
?>

in any html doc at any level (at least at any level at or below
the normal /public_html) and the footer appears fine in any
browser and with the folder "includes" (containing the footer
markup) at almost any level.

In order to get php includes working on a Windows server, I
manage by stating the detailed path to the folder. This involves
more careful vetting of all the paths in the various folders and
sub folder. It would be nice to have some construction that
worked like with a Unix server. Any suggested strategies please?

As long as it's accessed by the web-server, $_SERVER['DOCUMENT_ROOT']
should still work, I use it here on W2K all the time. If this does not
work for you, what's the actual content of $_SERVER['DOCUMENT_ROOT'] if
you echo it? And are you using Apache or ISS (or a totally different
server?)

(I post here rather than PHP ng because they seem altogether too
technical for it to be useful to me... though I might try. I
think I may have asked something similar in the past but the fact
is I am no nearer a solution. Just be a bit neater not to have to
vet all the paths...)

Tsssk, did they bother you about the include_path directive or something?
 
D

dorayme

Rik said:
On a Unix server, including the server on my Mac, you can use

<?php include ($_SERVER['DOCUMENT_ROOT'].'/includes/footer.inc');
?>

in any html doc at any level (at least at any level at or below
the normal /public_html) and the footer appears fine in any
browser and with the folder "includes" (containing the footer
markup) at almost any level.

In order to get php includes working on a Windows server, I
manage by stating the detailed path to the folder. This involves
more careful vetting of all the paths in the various folders and
sub folder. It would be nice to have some construction that
worked like with a Unix server. Any suggested strategies please?

As long as it's accessed by the web-server, $_SERVER['DOCUMENT_ROOT']
should still work,

It would be lovely if it worked for me. because then, there would
be a perfect model on my own home Apache server for the setup at
Optus.
I use it here on W2K all the time. If this does not
work for you, what's the actual content of $_SERVER['DOCUMENT_ROOT'] if
you echo it? And are you using Apache or ISS (or a totally different
server?)

Optus say: "All Optus shared web servers are built on a
combination of Windows Server 2003 and Internet Information
Services 6.0 technology... blah blah"

The truth is that I want to work with it and have at least one or
two sites on Windows servers to gain experience and not get all
wobbly and persuade every client to change to Unix (and cheaper
plans usually!). The ky has not fallen in yet. I just would like
to be able to better model the includes business to be quite
portable.

What do you suggest i actually do in plain and strict algorithmic
manner to answer your echo question?

Don't laugh but I added a line toi an html doc that goes:

<?php echo $_SERVER['DOCUMENT_ROOT']; ?>

uploaded the doc to the Optus server and accessed the doc in a
browser and got:

"PHP Warning: main(/includes/footer.inc) [function.main]: failed
to create stream: No such file or directory in
e:\inetpub\esvc000862\globalTest.html on line 13 PHP Warning:
main() [function.main]: Failed opening '/includes/footer.inc' for
inclusion (include_path='.;e:\php') in
e:\inetpub\esvc000862\globalTest.html on line 13"

How do I suck on that?
Tsssk, did they bother you about the include_path directive or something?

No, they are all very nice over there. It is painful letting new
people know how ignorant I am. With you lot, I hide nothing, no
amount of ill treatment deters me. You are a family I cling onto
for better or worse. It's horrible but what can I do? Where can I
go? I am like the battered wife with bad options. It is a total
disgrace but no one will blame me in the end.
 
J

J.O. Aho

dorayme said:
Rik said:
On a Unix server, including the server on my Mac, you can use
<?php include ($_SERVER['DOCUMENT_ROOT'].'/includes/footer.inc');
?>
in any html doc at any level (at least at any level at or below
the normal /public_html) and the footer appears fine in any
browser and with the folder "includes" (containing the footer
markup) at almost any level.
I use it here on W2K all the time. If this does not
work for you, what's the actual content of $_SERVER['DOCUMENT_ROOT'] if
you echo it? And are you using Apache or ISS (or a totally different
server?)
Optus say: "All Optus shared web servers are built on a
combination of Windows Server 2003 and Internet Information
Services 6.0 technology... blah blah"

http://us2.php.net/install.windows.iis

The problem comes from running PHP/CGI, the work around is to use ISAPI
instead of CGI. But that can be difficult to make a web hotel to change.
 
T

Toby A Inkster

dorayme said:
<?php include ($_SERVER['DOCUMENT_ROOT'].'/includes/footer.inc'); ?>

Unless you're moving files about *a lot*, or you enjoy including files
that include files that include files... just use relative paths. Easy.

<?php include './../../includes/footer.inc'; ?>

Personally, I prefer to create an includes directory, put it wherever the
hell I like (perhaps even outside the document root!) and include files
like this:

<?php include 'footer.inc'; ?>

So how does PHP know where footer.inc is kept? By setting the
"include_path" setting in "php.ini", ".htaccess", "httpd.conf"
or similar. Of course, if you are on shared hosting, you may
need to check that it is possible for you to adjust the
include_path.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
 
R

Rik

What do you suggest i actually do in plain and strict algorithmic
manner to answer your echo question?

Don't laugh but I added a line toi an html doc that goes:

<?php echo $_SERVER['DOCUMENT_ROOT']; ?>

uploaded the doc to the Optus server and accessed the doc in a
browser and got:

"PHP Warning: main(/includes/footer.inc) [function.main]: failed
to create stream: No such file or directory in
e:\inetpub\esvc000862\globalTest.html on line 13 PHP Warning:
main() [function.main]: Failed opening '/includes/footer.inc' for
inclusion (include_path='.;e:\php') in
e:\inetpub\esvc000862\globalTest.html on line 13"

How do I suck on that?

Well, it's like HTML/CSS questions, trim all unnecessary code. So make a
file _only_ containing <?php print_r($_SERVER); ?>, and we'll know a lot
more.

A possible <?php phpinfo(); ?> reachable somewhere would help a lot too,
then we can see most of the configuration.
 
Ad

Advertisements

D

dorayme

Toby A Inkster said:
dorayme said:
<?php include ($_SERVER['DOCUMENT_ROOT'].'/includes/footer.inc'); ?>

Unless you're moving files about *a lot*, or you enjoy including files
that include files that include files...

I don't and I don't.
just use relative paths. Easy.

<?php include './../../includes/footer.inc'; ?>

Which is exactly what I am doing on the Optus Windows server. But
not as easy as with the

<?php include ($_SERVER['DOCUMENT_ROOT'].'/includes/footer.inc');
?>

construction I use on my own server on this here machine nor on
other external Unix servers I maintain websites on.

As I understand it, this above construction relieves me of having
to work out the path to the includes folder on a per file basis.

The point of me wanting all this is not just to save a bit of
work but to be able to model the websites I have on Windows
servers on my own server here on the Mac. I get to keep one
website folder this way, not a number of them to suit different
servers...
Personally, I prefer to create an includes directory, put it wherever the
hell I like (perhaps even outside the document root!) and include files
like this:

<?php include 'footer.inc'; ?>

So how does PHP know where footer.inc is kept? By setting the
"include_path" setting in "php.ini", ".htaccess", "httpd.conf"
or similar. Of course, if you are on shared hosting, you may
need to check that it is possible for you to adjust the
include_path.

I am sort of following you here, the trouble is that I am a bit
lost over fine controls over the Windows servers concerned. They
are external and I do not _seem_ to have access to htaccess,
httpd.conf type thingies and before me is a horrible option,
having to ask Optus something and how the hell to phrase it and
let total strangers place me on an Andy Dingley scale of
cluelessness and get it wrong to boot. Even a martian has his
pride.
 
D

dorayme

Rik said:
What do you suggest i actually do in plain and strict algorithmic
manner to answer your echo question?

Don't laugh but I added a line toi an html doc that goes:

<?php echo $_SERVER['DOCUMENT_ROOT']; ?>

uploaded the doc to the Optus server and accessed the doc in a
browser and got:

"PHP Warning: main(/includes/footer.inc) [function.main]: failed
to create stream: No such file or directory in
e:\inetpub\esvc000862\globalTest.html on line 13 PHP Warning:
main() [function.main]: Failed opening '/includes/footer.inc' for
inclusion (include_path='.;e:\php') in
e:\inetpub\esvc000862\globalTest.html on line 13"

How do I suck on that?

Well, it's like HTML/CSS questions, trim all unnecessary code. So make a
file _only_ containing <?php print_r($_SERVER); ?>, and we'll know a lot
more.

It will be exactly the same. The remark I quoted was in direct
response to the php line I thought you were suggesting. Trim what?
A possible <?php phpinfo(); ?> reachable somewhere would help a lot too,
then we can see most of the configuration.

Yes, there may be clues here. Anything in particular that is
important out of the masses of info in the panels that come up?

There is:

System
Windows NT localhost 5.2 build 3790

Server API
CGI/FastCGI
Virtual Directory Support
enabled
Configuration File (php.ini) Path
E:\PHP\php.ini

and, here is a snippet from something to do with includes, roots
I notice:

include_path Local Value is .;e:\php Master Value is .;e:\php

(looking at this stuff makes me want to go and have 5 double
bourbons in a row quickly...)
 
Ad

Advertisements

J

Jim Moe

dorayme said:
I am sort of following you here, the trouble is that I am a bit
lost over fine controls over the Windows servers concerned.
Use the ini_set() function to change the value of include_path. The
disadvantage is that the setting only lasts for the session.

For a fully DIY method there is this. <base_dir.inc> provides a set of
custom directory strings created at the start of a session:
<?php
if (eregi('example.com', $_SERVER['SERVER_NAME'])) { // Local copy?
$base_dir1 = 'f:/pub/websites/';
$base_dir2 = $base_dir1 . 'sma-improved/';
}
else { // Must be the WWW
$base_dir1 = '/usr/local/apache/';
$base_dir2 = $base_dir1 . 'htdocs/';
}
?>
which is called by

function globals_init ($start_path)
{
global // If they weren't global before, they are now.
$base_dir1,
$base_dir2;
if (!isset($base_dir1)) {
$val = $start_path . 'base-dir.inc';
require($val); // Assigns $base_dir1 ..., here.
}
// ...whatever else you want set up...
}

This must be at the top of every PHP page:
require('./path/to/globals-init.inc');
globals_init('./path/to/base_dir/');

The advantage is the option to create a number of base directory paths.
It has its weaknesses, of course. The main being the need to prepend
base_dir1 (or base_dir2, ...) to the relative paths.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top