Problems getting "require" to work in PHP5 under Apache2

This is a discussion on Problems getting "require" to work in PHP5 under Apache2 within the PHP Language forums, part of the PHP Programming Forums category; The require() I'm using in a PHP script has stopped working after I moved from PHP4 and Apache 1....


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-19-2004
Mxsmanic
 
Posts: n/a
Default Problems getting "require" to work in PHP5 under Apache2

The require() I'm using in a PHP script has stopped working after I
moved from PHP4 and Apache 1.3.x to PHP5 and Apache 2.x. Now I get
messages like this:

Warning: main(/includes/ReloadScript.html) [function.main]: failed to
open stream: No such file or directory in
/usr/local/www/htdocs/main/AOLCompression.php on line 14

Fatal error: main() [function.require]: Failed opening required
'/includes/ReloadScript.html' (include_path='.:/usr/local/lib/php') in
/usr/local/www/htdocs/main/AOLCompression.php on line 14

I've seen references to the problems, but no workarounds or solutions.
What's the status? Is there a way around it?

--
Transpose hotmail and mxsmanic in my e-mail address to reach me directly.
Reply With Quote
  #2 (permalink)  
Old 12-20-2004
Andy Hassall
 
Posts: n/a
Default Re: Problems getting "require" to work in PHP5 under Apache2

On Sun, 19 Dec 2004 11:33:01 +0100, Mxsmanic <mxsmanic@hotmail.com> wrote:

>The require() I'm using in a PHP script has stopped working after I
>moved from PHP4 and Apache 1.3.x to PHP5 and Apache 2.x. Now I get
>messages like this:
>
>Warning: main(/includes/ReloadScript.html) [function.main]: failed to
>open stream: No such file or directory in
>/usr/local/www/htdocs/main/AOLCompression.php on line 14
>
>Fatal error: main() [function.require]: Failed opening required
>'/includes/ReloadScript.html' (include_path='.:/usr/local/lib/php') in
>/usr/local/www/htdocs/main/AOLCompression.php on line 14


According to the message it's looking for:

/includes/ReloadScript.html

Note the leading slash, indicating it's looking from the root directory of the
server. Are you sure this is correct?

Does the actual require() statement have something prepended to the path,
perhaps a variable or constant, that due to your change in configuration is now
blank? Post line 14 of /usr/local/www/htdocs/main/AOLCompression.php (and any
previous line relevant to it, i.e. showing definitions of variables).

On a related note; are you sure you want to require() an html file? Wouldn't
readfile() be more appropriate?

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Reply With Quote
  #3 (permalink)  
Old 12-20-2004
Mxsmanic
 
Posts: n/a
Default Re: Problems getting "require" to work in PHP5 under Apache2

Andy Hassall writes:

> According to the message it's looking for:
>
> /includes/ReloadScript.html
>
> Note the leading slash, indicating it's looking from the root directory of the
> server. Are you sure this is correct?


It worked previously (in php4 under Apache 1.3.x).

> Does the actual require() statement have something prepended to the path,
> perhaps a variable or constant, that due to your change in configuration is now
> blank? Post line 14 of /usr/local/www/htdocs/main/AOLCompression.php (and any
> previous line relevant to it, i.e. showing definitions of variables).


Yes. It had $DOCUMENT_ROOT prepended. That now appears to be blank;
I'm not sure why (I thought it was initialized to the document root from
the Apache configuration file). I changed this with php.ini, but it
still didn't work.

The original line looks like this in the script:

<?PHP require($DOCUMENT_ROOT."/includes/ReloadScript.html"); ?>

> On a related note; are you sure you want to require() an html file? Wouldn't
> readfile() be more appropriate?


I originally wanted to make sure the include was there. The idea was to
emulate a #include line in a PHP script (since PHP scripts cannot use
SSI).

However, as an experiment after looking around the Net, I changed it to
this:

<?PHP require($_SERVER["DOCUMENT_ROOT"]."/includes/counter"); ?>

For some reason, this appears to work. I don't know why. The contents
of $_SERVER["DOCUMENT_ROOT"] should be the same as $DOCUMENT_ROOT,
right? Anyway, this is either a workaround or a fix (not sure which at
this point), because it eliminates the error. Did something change in
later versions of PHP4 or PHP5 (I was getting the same error with the
latest version of PHP4, so it wasn't just going to PHP5 that did it).

Also, when will the very latest version of PHP5 (5.0.3 or above) install
correctly? I'm still running 5.0.1 because that's apparently the last
version with a correct make install script (for FreeBSD UNIX).

--
Transpose hotmail and mxsmanic in my e-mail address to reach me directly.
Reply With Quote
  #4 (permalink)  
Old 12-20-2004
Wayne
 
Posts: n/a
Default Re: Problems getting "require" to work in PHP5 under Apache2

On Mon, 20 Dec 2004 05:56:50 +0100, Mxsmanic <mxsmanic@hotmail.com>
wrote:

>However, as an experiment after looking around the Net, I changed it to
>this:
>
><?PHP require($_SERVER["DOCUMENT_ROOT"]."/includes/counter"); ?>
>
>For some reason, this appears to work. I don't know why. The contents
>of $_SERVER["DOCUMENT_ROOT"] should be the same as $DOCUMENT_ROOT,
>right? Anyway, this is either a workaround or a fix (not sure which at
>this point), because it eliminates the error. Did something change in
>later versions of PHP4 or PHP5 (I was getting the same error with the
>latest version of PHP4, so it wasn't just going to PHP5 that did it).


Only with register_globals enabled does $DOCUMENT_ROOT =
$_SERVER['DOCUMENT_ROOT']. Register_globals is considered a security
risk and is disabled in later version of PHP.

All this is explained in the manual.

Reply With Quote
  #5 (permalink)  
Old 12-20-2004
Mxsmanic
 
Posts: n/a
Default Re: Problems getting "require" to work in PHP5 under Apache2

Wayne writes:

> All this is explained in the manual.


I wish there were 200 hours in a day so that I could actually read
manuals.

--
Transpose hotmail and mxsmanic in my e-mail address to reach me directly.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:41 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0