469,964 Members | 1,399 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,964 developers. It's quick & easy.

include("/main.php") won't work on a hosting machine

if you are just a users among the 100s of users on a hosting machines,
then if you do a include("/main.php"); it won't include the file
but will say

Failed opening required '/main.php' (include_path='.:/usr/local/nf/
lib/php')

it seems ok to include("../main.php"); except the file will not work
if moved from www.abc.com/movies to a new location of
www.abc.com/movies/little-mermaid is there a better solution for
this?

Jun 19 '07 #1
5 3583
Summercoolness wrote:
is there a better solution for
this?
Google: .htaccess php_value include_path

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 115 days, 15:25.]

dict, thes & ency
http://tobyinkster.co.uk/blog/2007/0...ict-thes-ency/
Jun 19 '07 #2
Su************@gmail.com wrote:
if you are just a users among the 100s of users on a hosting machines,
then if you do a include("/main.php"); it won't include the file
but will say

Failed opening required '/main.php' (include_path='.:/usr/local/nf/
lib/php')

it seems ok to include("../main.php"); except the file will not work
if moved from www.abc.com/movies to a new location of
www.abc.com/movies/little-mermaid is there a better solution for
this?
include ($_SERVER['DOCUMENT_ROOT']) . '/main.php');

That way you don't have to worry about include paths, which some hosts
don't allow you to change. It also works on IIS, which doesn't have
..htaccess.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 19 '07 #3
Jerry Stuckle wrote:
Su************@gmail.com wrote:
>if you are just a users among the 100s of users on a hosting machines,
then if you do a include("/main.php"); it won't include the file
but will say

Failed opening required '/main.php' (include_path='.:/usr/local/nf/
lib/php')

it seems ok to include("../main.php"); except the file will not work
if moved from www.abc.com/movies to a new location of
www.abc.com/movies/little-mermaid is there a better solution for
this?


include ($_SERVER['DOCUMENT_ROOT']) . '/main.php');

That way you don't have to worry about include paths, which some hosts
don't allow you to change. It also works on IIS, which doesn't have
.htaccess.

Wow. Serendipity? Synchronicity? ... I was about to ask this very same
question ... downloaded today's new messages, and I see someone did it
for me (thanks to summercoolness).

And it is also came to me just this morning that ....

include "{$_SERVER['DOCUMENT_ROOT']}/file_to_include.php";

.... was the solution.

But .... do you happen to understand why "/" does not work with include
to indicate the root dir?

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
*****************************
Jun 19 '07 #4
..oO(Chuck Anderson)
>And it is also came to me just this morning that ....

include "{$_SERVER['DOCUMENT_ROOT']}/file_to_include.php";

... was the solution.

But .... do you happen to understand why "/" does not work with include
to indicate the root dir?
You mean something like

include '/foo.php'; ?

The document root of the webserver ($_SERVER['DOCUMENT_ROOT']) and the
root of the server's file system are two completely different things.
The above statement would look for the file in the server's physical
root directory, where no normal user should have write access - it's a
system-only area. The webserver's root directory is usually something
like '/home/username/public_html', where you can do whatever you want.

Micha
Jun 19 '07 #5
Michael Fesser wrote:
.oO(Chuck Anderson)

>And it is also came to me just this morning that ....

include "{$_SERVER['DOCUMENT_ROOT']}/file_to_include.php";

... was the solution.

But .... do you happen to understand why "/" does not work with include
to indicate the root dir?

You mean something like

include '/foo.php'; ?

The document root of the webserver ($_SERVER['DOCUMENT_ROOT']) and the
root of the server's file system are two completely different things.
The above statement would look for the file in the server's physical
root directory, where no normal user should have write access - it's a
system-only area. The webserver's root directory is usually something
like '/home/username/public_html', where you can do whatever you want.

Micha
Thanks. I get it. This one always gets me (maybe no longer now). I have
always gotten it confused with hyperlinks (where / *is* the web root).

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
*****************************
Jun 19 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

43 posts views Thread by steve | last post: by
2 posts views Thread by steve | last post: by
18 posts views Thread by Tuckers | last post: by
3 posts views Thread by emilper | last post: by
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.